refactor: add helper function get_selection_or_select_word
This commit is contained in:
parent
5d7323bfe7
commit
d7c02f0700
1 changed files with 13 additions and 12 deletions
|
|
@ -7257,15 +7257,21 @@ pub const Editor = struct {
|
||||||
.arguments = &.{.integer},
|
.arguments = &.{.integer},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
fn get_selection_or_select_word(self: *Self, root: Buffer.Root, cursel: *CurSel) error{Stop}!*Selection {
|
||||||
|
if (cursel.selection) |*sel| {
|
||||||
|
return sel;
|
||||||
|
} else {
|
||||||
|
var sel = cursel.enable_selection(root, self.metrics);
|
||||||
|
try move_cursor_word_begin(root, &sel.begin, self.metrics);
|
||||||
|
try move_cursor_word_end(root, &sel.end, self.metrics);
|
||||||
|
return sel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn to_upper_cursel(self: *Self, root_: Buffer.Root, cursel: *CurSel, allocator: Allocator) error{Stop}!Buffer.Root {
|
fn to_upper_cursel(self: *Self, root_: Buffer.Root, cursel: *CurSel, allocator: Allocator) error{Stop}!Buffer.Root {
|
||||||
var root = root_;
|
var root = root_;
|
||||||
const saved = cursel.*;
|
const saved = cursel.*;
|
||||||
const sel = if (cursel.selection) |*sel| sel else ret: {
|
const sel = try self.get_selection_or_select_word(root, cursel);
|
||||||
var sel = cursel.enable_selection(root, self.metrics);
|
|
||||||
move_cursor_word_begin(root, &sel.begin, self.metrics) catch return error.Stop;
|
|
||||||
move_cursor_word_end(root, &sel.end, self.metrics) catch return error.Stop;
|
|
||||||
break :ret sel;
|
|
||||||
};
|
|
||||||
var sfa = std.heap.stackFallback(4096, self.allocator);
|
var sfa = std.heap.stackFallback(4096, self.allocator);
|
||||||
const sfa_allocator = sfa.get();
|
const sfa_allocator = sfa.get();
|
||||||
const cut_text = copy_selection(root, sel.*, sfa_allocator, self.metrics) catch return error.Stop;
|
const cut_text = copy_selection(root, sel.*, sfa_allocator, self.metrics) catch return error.Stop;
|
||||||
|
|
@ -7289,12 +7295,7 @@ pub const Editor = struct {
|
||||||
fn to_lower_cursel(self: *Self, root_: Buffer.Root, cursel: *CurSel, buffer_allocator: Allocator) error{Stop}!Buffer.Root {
|
fn to_lower_cursel(self: *Self, root_: Buffer.Root, cursel: *CurSel, buffer_allocator: Allocator) error{Stop}!Buffer.Root {
|
||||||
var root = root_;
|
var root = root_;
|
||||||
const saved = cursel.*;
|
const saved = cursel.*;
|
||||||
const sel = if (cursel.selection) |*sel| sel else ret: {
|
const sel = try self.get_selection_or_select_word(root, cursel);
|
||||||
var sel = cursel.enable_selection(root, self.metrics);
|
|
||||||
move_cursor_word_begin(root, &sel.begin, self.metrics) catch return error.Stop;
|
|
||||||
move_cursor_word_end(root, &sel.end, self.metrics) catch return error.Stop;
|
|
||||||
break :ret sel;
|
|
||||||
};
|
|
||||||
var sfa = std.heap.stackFallback(4096, self.allocator);
|
var sfa = std.heap.stackFallback(4096, self.allocator);
|
||||||
const sfa_allocator = sfa.get();
|
const sfa_allocator = sfa.get();
|
||||||
const cut_text = copy_selection(root, sel.*, sfa_allocator, self.metrics) catch return error.Stop;
|
const cut_text = copy_selection(root, sel.*, sfa_allocator, self.metrics) catch return error.Stop;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue