refactor: move get_replacement_selection to completion_dropdown
This commit is contained in:
parent
d4eb0d046c
commit
29ac7849c7
2 changed files with 16 additions and 17 deletions
|
|
@ -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) }))
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue