refactor: add support for backspace during completion

This commit is contained in:
CJ van den Berg 2025-12-23 23:53:14 +01:00
parent b2996cddbd
commit 911fc3160a
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
3 changed files with 22 additions and 3 deletions

View file

@ -353,6 +353,15 @@ pub fn Create(options: type) type {
return matches.items.len;
}
fn delete_code_point(self: *Self) !void {
if (self.query.items.len > 0) {
self.query.shrinkRetainingCapacity(self.query.items.len - tui.egc_last(self.query.items).len);
if (@hasDecl(options, "update_query"))
options.update_query(self, self.query.items);
}
try self.start_query(0);
}
fn insert_code_point(self: *Self, c: u32) !void {
var buf: [6]u8 = undefined;
const bytes = try input.ucs32_to_utf8(&[_]u32{c}, &buf);
@ -523,6 +532,11 @@ pub fn Create(options: type) type {
}
pub const palette_menu_cancel_meta: Meta = .{};
pub fn overlay_delete_backwards(self: *Self, _: Ctx) Result {
self.delete_code_point() catch |e| return tp.exit_error(e, @errorReturnTrace());
}
pub const overlay_delete_backwards_meta: Meta = .{ .description = "Delete backwards" };
pub fn overlay_insert_code_point(self: *Self, ctx: Ctx) Result {
var egc: u32 = 0;
if (!try ctx.args.match(.{tp.extract(&egc)}))