refactor: simplify disable_selection to never move the cursor
This commit is contained in:
parent
a15ceeb4a7
commit
1755ecb3dd
1 changed files with 5 additions and 23 deletions
|
|
@ -137,37 +137,19 @@ pub const CurSel = struct {
|
|||
}
|
||||
|
||||
fn to_selection_inclusive(self: *const Self, root: Buffer.Root, metrics: Buffer.Metrics) Selection {
|
||||
return if (self.selection) |sel|
|
||||
sel
|
||||
else cod: {
|
||||
var sel = Selection.from_cursor(&self.cursor);
|
||||
sel.end.move_right(root, metrics) catch {};
|
||||
break :cod sel;
|
||||
};
|
||||
return self.selection orelse Selection.from_cursor_inclusive(&self.cursor, root, metrics);
|
||||
}
|
||||
|
||||
pub fn disable_selection(self: *Self, root: Buffer.Root, metrics: Buffer.Metrics) void {
|
||||
switch (tui.get_selection_style()) {
|
||||
.normal => self.disable_selection_normal(),
|
||||
.inclusive => self.disable_selection_inclusive(root, metrics),
|
||||
}
|
||||
pub fn disable_selection(self: *Self, _: Buffer.Root, _: Buffer.Metrics) void {
|
||||
self.selection = null;
|
||||
}
|
||||
|
||||
pub fn disable_selection_normal(self: *Self) void {
|
||||
self.selection = null;
|
||||
}
|
||||
|
||||
fn disable_selection_inclusive(self: *Self, root: Buffer.Root, metrics: Buffer.Metrics) void {
|
||||
if (self.selection) |sel| {
|
||||
if (!sel.is_reversed()) self.cursor.move_left(root, metrics) catch {};
|
||||
self.selection = null;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn check_selection(self: *Self, root: Buffer.Root, metrics: Buffer.Metrics) void {
|
||||
if (self.selection) |sel| if (sel.empty()) {
|
||||
self.disable_selection(root, metrics);
|
||||
};
|
||||
pub fn check_selection(self: *Self, _: Buffer.Root, _: Buffer.Metrics) void {
|
||||
self.selection = if (self.selection) |sel| if (sel.empty()) null else sel else null;
|
||||
}
|
||||
|
||||
fn expand_selection_to_line(self: *Self, root: Buffer.Root, metrics: Buffer.Metrics) *Selection {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue