Compare commits

...

2 commits

Author SHA1 Message Date
a3ea183ba1
fix: completion dropdown must dupe completion data
Because it might be erased by the next completion response.

closes #477
2026-02-01 20:14:16 +01:00
d07389b8ee
fix: wrong prefix for single line reflows 2026-02-01 20:00:01 +01:00
2 changed files with 14 additions and 2 deletions

View file

@ -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];

View file

@ -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();
}