Compare commits
2 commits
9c4f30c4ee
...
a3ea183ba1
| Author | SHA1 | Date | |
|---|---|---|---|
| a3ea183ba1 | |||
| d07389b8ee |
2 changed files with 14 additions and 2 deletions
|
|
@ -60,8 +60,16 @@ fn detect_prefix(text: []const u8) Prefix {
|
|||
var lines = std.mem.splitScalar(u8, text, '\n');
|
||||
const line1 = lines.next() orelse return .{};
|
||||
var prefix: []const u8 = line1;
|
||||
while (lines.next()) |line|
|
||||
var count: usize = 0;
|
||||
while (lines.next()) |line| {
|
||||
prefix = lcp(prefix, line);
|
||||
count += 1;
|
||||
}
|
||||
if (count < 1) return .{
|
||||
.len = 0,
|
||||
.first = &.{},
|
||||
.continuation = &.{},
|
||||
};
|
||||
|
||||
if (line1.len > prefix.len + 2 and line1[prefix.len] == '-' and line1[prefix.len + 1] == ' ') {
|
||||
const first = line1[0 .. prefix.len + 2];
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ pub const ValueType = struct {
|
|||
query: ?Buffer.Selection = null,
|
||||
last_query: ?[]const u8 = null,
|
||||
commands: command.Collection(cmds) = undefined,
|
||||
data: []const u8 = &.{},
|
||||
};
|
||||
pub const defaultValue: ValueType = .{};
|
||||
|
||||
|
|
@ -53,7 +54,9 @@ pub fn load_entries(self: *Type) !usize {
|
|||
|
||||
self.value.cursor = self.value.editor.get_primary().cursor;
|
||||
self.value.query = null;
|
||||
var iter: []const u8 = self.value.editor.completions.data.items;
|
||||
self.allocator.free(self.value.data);
|
||||
self.value.data = try self.allocator.dupe(u8, self.value.editor.completions.data.items);
|
||||
var iter: []const u8 = self.value.data;
|
||||
while (iter.len > 0) {
|
||||
var cbor_item: []const u8 = undefined;
|
||||
if (!try cbor.matchValue(&iter, cbor.extract_cbor(&cbor_item))) return error.BadCompletion;
|
||||
|
|
@ -90,6 +93,7 @@ pub fn load_entries(self: *Type) !usize {
|
|||
}
|
||||
|
||||
pub fn deinit(self: *Type) void {
|
||||
self.allocator.free(self.value.data);
|
||||
if (self.value.last_query) |p| self.allocator.free(p);
|
||||
self.value.commands.deinit();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue