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

@ -278,11 +278,24 @@ const Range = struct { start: Position, end: Position };
const Position = struct { line: usize, character: usize };
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 {
self.menu.activate_selected();
fn get_replacement_selection(editor: *ed.Editor, insert_: ?Buffer.Selection, replace_: ?Buffer.Selection) ?Buffer.Selection {
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 {