refactor: add support for backspace during completion
This commit is contained in:
parent
b2996cddbd
commit
911fc3160a
3 changed files with 22 additions and 3 deletions
|
|
@ -385,7 +385,8 @@
|
||||||
["ctrl+up", "palette_menu_up"],
|
["ctrl+up", "palette_menu_up"],
|
||||||
["ctrl+down", "palette_menu_down"],
|
["ctrl+down", "palette_menu_down"],
|
||||||
["ctrl+enter", "palette_menu_activate"],
|
["ctrl+enter", "palette_menu_activate"],
|
||||||
["tab", "palette_menu_complete"]
|
["tab", "palette_menu_complete"],
|
||||||
|
["backspace", "overlay_delete_backwards"]
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"overlay/dropdown": {
|
"overlay/dropdown": {
|
||||||
|
|
@ -398,7 +399,8 @@
|
||||||
["up", "palette_menu_up"],
|
["up", "palette_menu_up"],
|
||||||
["down", "palette_menu_down"],
|
["down", "palette_menu_down"],
|
||||||
["enter", "palette_menu_activate"],
|
["enter", "palette_menu_activate"],
|
||||||
["tab", "palette_menu_complete"]
|
["tab", "palette_menu_complete"],
|
||||||
|
["backspace", "overlay_delete_backwards"]
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"mini/numeric": {
|
"mini/numeric": {
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,10 @@ pub fn update_query(self: *Type, query: []const u8) void {
|
||||||
const primary = editor.get_primary();
|
const primary = editor.get_primary();
|
||||||
primary.selection = get_insert_selection(self, editor.get_primary().cursor);
|
primary.selection = get_insert_selection(self, editor.get_primary().cursor);
|
||||||
const b = editor.buf_for_update() catch return;
|
const b = editor.buf_for_update() catch return;
|
||||||
const root_ = editor.insert(b.root, primary, query, b.allocator) catch return;
|
const root_ = if (query.len > 0)
|
||||||
|
editor.insert(b.root, primary, query, b.allocator) catch return
|
||||||
|
else
|
||||||
|
editor.delete_selection(b.root, primary, b.allocator) catch return;
|
||||||
self.value.cursor = editor.get_primary().cursor;
|
self.value.cursor = editor.get_primary().cursor;
|
||||||
if (self.value.replace) |*sel| sel.* = .{ .begin = sel.begin, .end = self.value.cursor };
|
if (self.value.replace) |*sel| sel.* = .{ .begin = sel.begin, .end = self.value.cursor };
|
||||||
primary.selection = null;
|
primary.selection = null;
|
||||||
|
|
|
||||||
|
|
@ -353,6 +353,15 @@ pub fn Create(options: type) type {
|
||||||
return matches.items.len;
|
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 {
|
fn insert_code_point(self: *Self, c: u32) !void {
|
||||||
var buf: [6]u8 = undefined;
|
var buf: [6]u8 = undefined;
|
||||||
const bytes = try input.ucs32_to_utf8(&[_]u32{c}, &buf);
|
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 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 {
|
pub fn overlay_insert_code_point(self: *Self, ctx: Ctx) Result {
|
||||||
var egc: u32 = 0;
|
var egc: u32 = 0;
|
||||||
if (!try ctx.args.match(.{tp.extract(&egc)}))
|
if (!try ctx.args.match(.{tp.extract(&egc)}))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue