feat: cancel inline completion with backspace

closes #447
This commit is contained in:
CJ van den Berg 2026-01-12 19:33:37 +01:00
parent da942fe640
commit 4273ab790c
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
2 changed files with 17 additions and 0 deletions

View file

@ -130,6 +130,16 @@ pub fn update_query(self: *Type, query: []const u8) void {
return; return;
} }
pub fn delete_word_empty(self: *Type) void {
cancel(self) catch return;
tp.self_pid().send(.{ "cmd", "delete_word_left" }) catch |e| self.logger.err(module_name, e);
}
pub fn delete_empty(self: *Type) void {
cancel(self) catch return;
tp.self_pid().send(.{ "cmd", "smart_delete_backward" }) catch |e| self.logger.err(module_name, e);
}
fn get_insert_selection(self: *Type, cursor: ed.Cursor) ed.Selection { fn get_insert_selection(self: *Type, cursor: ed.Cursor) ed.Selection {
return if (self.value.replace) |sel| return if (self.value.replace) |sel|
sel sel

View file

@ -354,6 +354,10 @@ pub fn Create(options: type) type {
} }
fn delete_word(self: *Self) !void { fn delete_word(self: *Self) !void {
if (self.query.items.len == 0 and @hasDecl(options, "delete_word_empty")) {
options.delete_word_empty(self);
return;
}
if (std.mem.lastIndexOfAny(u8, self.query.items, "/\\. -_")) |pos| { if (std.mem.lastIndexOfAny(u8, self.query.items, "/\\. -_")) |pos| {
self.query.shrinkRetainingCapacity(pos); self.query.shrinkRetainingCapacity(pos);
} else { } else {
@ -369,6 +373,9 @@ pub fn Create(options: type) type {
self.query.shrinkRetainingCapacity(self.query.items.len - tui.egc_last(self.query.items).len); self.query.shrinkRetainingCapacity(self.query.items.len - tui.egc_last(self.query.items).len);
if (@hasDecl(options, "update_query")) if (@hasDecl(options, "update_query"))
options.update_query(self, self.query.items); options.update_query(self, self.query.items);
} else {
if (@hasDecl(options, "delete_empty"))
options.delete_empty(self);
} }
try self.start_query(0); try self.start_query(0);
} }