refactor: move get_replacement_selection to completion_dropdown

This commit is contained in:
CJ van den Berg 2026-01-30 13:55:23 +01:00
parent d4eb0d046c
commit 29ac7849c7
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
2 changed files with 16 additions and 17 deletions

View file

@ -6615,20 +6615,6 @@ pub const Editor = struct {
return open_completions; return open_completions;
} }
pub fn get_completion_replacement_selection(self: *Self, insert_: ?Selection, replace_: ?Selection) ?Selection {
const replace = replace_ orelse insert_ orelse return null;
var sel = replace.from_pos(self.buf_root() catch return null, self.metrics);
sel.normalize();
const cursor = self.get_primary().cursor;
return switch (tui.config().completion_insert_mode) {
.insert => if (self.get_primary().cursor.within(sel))
.{ .begin = sel.begin, .end = cursor }
else
sel,
.replace => sel,
};
}
pub fn select(self: *Self, ctx: Context) Result { pub fn select(self: *Self, ctx: Context) Result {
var sel: Selection = .{}; var sel: Selection = .{};
if (!try ctx.args.match(.{ tp.extract(&sel.begin.row), tp.extract(&sel.begin.col), tp.extract(&sel.end.row), tp.extract(&sel.end.col) })) if (!try ctx.args.match(.{ tp.extract(&sel.begin.row), tp.extract(&sel.begin.col), tp.extract(&sel.end.row), tp.extract(&sel.end.col) }))

View file

@ -278,11 +278,24 @@ const Range = struct { start: Position, end: Position };
const Position = struct { line: usize, character: usize }; const Position = struct { line: usize, character: usize };
pub fn get_replace_selection(editor: *ed.Editor, values: Values) ?Buffer.Selection { pub fn get_replace_selection(editor: *ed.Editor, values: Values) ?Buffer.Selection {
return editor.get_completion_replacement_selection(values.insert, values.replace); return get_replacement_selection(editor, values.insert, values.replace);
} }
pub fn complete(self: *Type, _: ?*Type.ButtonType) !void { fn get_replacement_selection(editor: *ed.Editor, insert_: ?Buffer.Selection, replace_: ?Buffer.Selection) ?Buffer.Selection {
self.menu.activate_selected(); const pos = switch (tui.config().completion_insert_mode) {
.replace => replace_ orelse insert_ orelse return null,
.insert => insert_ orelse replace_ orelse return null,
};
var sel = pos.from_pos(editor.buf_root() catch return null, editor.metrics);
sel.normalize();
const cursor = editor.get_primary().cursor;
return switch (tui.config().completion_insert_mode) {
.insert => if (editor.get_primary().cursor.within(sel))
.{ .begin = sel.begin, .end = cursor }
else
sel,
.replace => sel,
};
} }
fn get_insert_selection(self: *Type, values: Values, cursor: ed.Cursor) ed.Selection { fn get_insert_selection(self: *Type, values: Values, cursor: ed.Cursor) ed.Selection {