Compare commits
2 commits
7520289442
...
9c8d5f8aab
| Author | SHA1 | Date | |
|---|---|---|---|
| 9c8d5f8aab | |||
| d974d510b1 |
2 changed files with 18 additions and 8 deletions
|
|
@ -2458,7 +2458,7 @@ pub const Editor = struct {
|
||||||
const cursel_operator_mut = *const fn (self: *Self, root: Buffer.Root, cursel: *CurSel, allocator: Allocator) error{Stop}!Buffer.Root;
|
const cursel_operator_mut = *const fn (self: *Self, root: Buffer.Root, cursel: *CurSel, allocator: Allocator) error{Stop}!Buffer.Root;
|
||||||
const cursel_operator_mut_arg = *const fn (self: *Self, root: Buffer.Root, cursel: *CurSel, allocator: Allocator, ctx: Context) error{Stop}!Buffer.Root;
|
const cursel_operator_mut_arg = *const fn (self: *Self, root: Buffer.Root, cursel: *CurSel, allocator: Allocator, ctx: Context) error{Stop}!Buffer.Root;
|
||||||
|
|
||||||
pub fn is_not_word_char(c: []const u8) bool {
|
pub fn is_non_word_char(c: []const u8) bool {
|
||||||
if (c.len == 0) return true;
|
if (c.len == 0) return true;
|
||||||
return switch (c[0]) {
|
return switch (c[0]) {
|
||||||
' ' => true,
|
' ' => true,
|
||||||
|
|
@ -2493,7 +2493,7 @@ pub const Editor = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_word_char(c: []const u8) bool {
|
pub fn is_word_char(c: []const u8) bool {
|
||||||
return !is_not_word_char(c);
|
return !is_non_word_char(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_word_char_at_cursor(root: Buffer.Root, cursor: *const Cursor, metrics: Buffer.Metrics) bool {
|
fn is_word_char_at_cursor(root: Buffer.Root, cursor: *const Cursor, metrics: Buffer.Metrics) bool {
|
||||||
|
|
@ -2501,7 +2501,7 @@ pub const Editor = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_non_word_char_at_cursor(root: Buffer.Root, cursor: *const Cursor, metrics: Buffer.Metrics) bool {
|
pub fn is_non_word_char_at_cursor(root: Buffer.Root, cursor: *const Cursor, metrics: Buffer.Metrics) bool {
|
||||||
return cursor.test_at(root, is_not_word_char, metrics);
|
return cursor.test_at(root, is_non_word_char, metrics);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_word_boundary_left(root: Buffer.Root, cursor: *const Cursor, metrics: Buffer.Metrics) bool {
|
pub fn is_word_boundary_left(root: Buffer.Root, cursor: *const Cursor, metrics: Buffer.Metrics) bool {
|
||||||
|
|
@ -4995,7 +4995,7 @@ pub const Editor = struct {
|
||||||
_ = self.pop_tabstop();
|
_ = self.pop_tabstop();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_trigger_left(root: Buffer.Root, cursor: *const Cursor, metrics: Buffer.Metrics, triggers: []const TriggerSymbol) bool {
|
fn is_completion_boundary_left(root: Buffer.Root, cursor: *const Cursor, metrics: Buffer.Metrics, triggers: []const TriggerSymbol) bool {
|
||||||
if (cursor.col == 0) return true;
|
if (cursor.col == 0) return true;
|
||||||
var next = cursor.*;
|
var next = cursor.*;
|
||||||
next.move_left(root, metrics) catch return true;
|
next.move_left(root, metrics) catch return true;
|
||||||
|
|
@ -5007,17 +5007,27 @@ pub const Editor = struct {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_completion_boundary_at_cursor(root: Buffer.Root, cursor: *const Cursor, metrics: Buffer.Metrics, triggers: []const TriggerSymbol) bool {
|
||||||
|
var pos = cursor.*;
|
||||||
|
const egc, _, _ = pos.egc_at(root, metrics) catch return true;
|
||||||
|
if (is_non_word_char(egc)) return true;
|
||||||
|
const c = egc[0];
|
||||||
|
for (triggers) |t| if (c == t.char) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn guest_completion_range(self: *Self) Selection {
|
pub fn guest_completion_range(self: *Self) Selection {
|
||||||
var cursel = self.get_primary().*;
|
var cursel = self.get_primary().*;
|
||||||
var sel = Selection.from_cursor(&cursel.cursor);
|
var sel = Selection.from_cursor(&cursel.cursor);
|
||||||
if (cursel.cursor.col == 0) return sel;
|
if (cursel.cursor.col == 0) return sel;
|
||||||
const root = self.buf_root() catch return sel;
|
const root = self.buf_root() catch return sel;
|
||||||
|
|
||||||
while (!is_trigger_left(root, &sel.begin, self.metrics, self.get_event_triggers(.insert).items))
|
while (!is_completion_boundary_left(root, &sel.begin, self.metrics, self.get_event_triggers(.insert).items))
|
||||||
move_cursor_left(root, &sel.begin, self.metrics) catch return sel;
|
move_cursor_left(root, &sel.begin, self.metrics) catch return sel;
|
||||||
|
|
||||||
if (tui.config().completion_insert_mode == .replace)
|
if (tui.config().completion_insert_mode == .replace)
|
||||||
move_cursor_word_right(root, &sel.end, self.metrics) catch return sel;
|
while (!is_completion_boundary_at_cursor(root, &sel.end, self.metrics, self.get_event_triggers(.insert).items))
|
||||||
|
move_cursor_right(root, &sel.end, self.metrics) catch return sel;
|
||||||
return sel;
|
return sel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -829,8 +829,8 @@ fn move_cursor_word_left_helix(root: Buffer.Root, cursor: *Cursor, metrics: Buff
|
||||||
var next_next = next;
|
var next_next = next;
|
||||||
next_next.move_left(root, metrics) catch return;
|
next_next.move_left(root, metrics) catch return;
|
||||||
|
|
||||||
const cur = next.test_at(root, Editor.is_not_word_char, metrics);
|
const cur = next.test_at(root, Editor.is_non_word_char, metrics);
|
||||||
const nxt = next_next.test_at(root, Editor.is_not_word_char, metrics);
|
const nxt = next_next.test_at(root, Editor.is_non_word_char, metrics);
|
||||||
if (cur != nxt) {
|
if (cur != nxt) {
|
||||||
try Editor.move_cursor_left(root, cursor, metrics);
|
try Editor.move_cursor_left(root, cursor, metrics);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue