Compare commits
4 commits
77379a58cf
...
d8fa1b28aa
| Author | SHA1 | Date | |
|---|---|---|---|
| d8fa1b28aa | |||
| 3051cc3b86 | |||
| 9729bae7be | |||
| d0abaaee2a |
5 changed files with 32 additions and 2 deletions
|
|
@ -54,6 +54,7 @@ start_debugger_on_crash: bool = false,
|
||||||
|
|
||||||
completion_trigger: CompletionTrigger = .automatic,
|
completion_trigger: CompletionTrigger = .automatic,
|
||||||
completion_style: CompletionStyle = .dropdown,
|
completion_style: CompletionStyle = .dropdown,
|
||||||
|
completion_insert_mode: CompletionInsertMode = .insert,
|
||||||
|
|
||||||
widget_style: WidgetStyle = .compact,
|
widget_style: WidgetStyle = .compact,
|
||||||
palette_style: WidgetStyle = .bars_top_bottom,
|
palette_style: WidgetStyle = .bars_top_bottom,
|
||||||
|
|
@ -182,6 +183,11 @@ pub const CompletionStyle = enum {
|
||||||
dropdown,
|
dropdown,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const CompletionInsertMode = enum {
|
||||||
|
insert,
|
||||||
|
replace,
|
||||||
|
};
|
||||||
|
|
||||||
pub const Alignment = enum {
|
pub const Alignment = enum {
|
||||||
left,
|
left,
|
||||||
right,
|
right,
|
||||||
|
|
|
||||||
|
|
@ -6408,6 +6408,19 @@ pub const Editor = struct {
|
||||||
self.completion_is_complete = is_incomplete;
|
self.completion_is_complete = is_incomplete;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_completion_replacement_selection(self: *Self, replace: Selection) ?Selection {
|
||||||
|
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) }))
|
||||||
|
|
|
||||||
|
|
@ -276,7 +276,7 @@ fn get_replace_selection(replace: Buffer.Selection) ?Buffer.Selection {
|
||||||
return if (replace.empty())
|
return if (replace.empty())
|
||||||
null
|
null
|
||||||
else if (tui.get_active_editor()) |edt|
|
else if (tui.get_active_editor()) |edt|
|
||||||
replace.from_pos(edt.buf_root() catch return null, edt.metrics)
|
edt.get_completion_replacement_selection(replace)
|
||||||
else
|
else
|
||||||
replace;
|
replace;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -205,7 +205,7 @@ fn get_replace_selection(replace: Buffer.Selection) ?Buffer.Selection {
|
||||||
return if (replace.empty())
|
return if (replace.empty())
|
||||||
null
|
null
|
||||||
else if (tui.get_active_editor()) |edt|
|
else if (tui.get_active_editor()) |edt|
|
||||||
replace.from_pos(edt.buf_root() catch return null, edt.metrics)
|
edt.get_completion_replacement_selection(replace)
|
||||||
else
|
else
|
||||||
replace;
|
replace;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1150,6 +1150,17 @@ const cmds = struct {
|
||||||
}
|
}
|
||||||
pub const toggle_completion_trigger_meta: Meta = .{ .description = "Toggle auto completion" };
|
pub const toggle_completion_trigger_meta: Meta = .{ .description = "Toggle auto completion" };
|
||||||
|
|
||||||
|
pub fn toggle_completion_insert_mode(self: *Self, _: Ctx) Result {
|
||||||
|
self.config_.completion_insert_mode = switch (self.config_.completion_insert_mode) {
|
||||||
|
.insert => .replace,
|
||||||
|
.replace => .insert,
|
||||||
|
};
|
||||||
|
defer self.logger.print("completion insert mode {t}", .{self.config_.completion_insert_mode});
|
||||||
|
try save_config();
|
||||||
|
resize();
|
||||||
|
}
|
||||||
|
pub const toggle_completion_insert_mode_meta: Meta = .{ .description = "Toggle completion insert mode" };
|
||||||
|
|
||||||
pub fn toggle_keybind_hints(self: *Self, _: Ctx) Result {
|
pub fn toggle_keybind_hints(self: *Self, _: Ctx) Result {
|
||||||
self.hint_mode = switch (self.hint_mode) {
|
self.hint_mode = switch (self.hint_mode) {
|
||||||
.all => .prefix,
|
.all => .prefix,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue