core: checkResetSelSwitch converted

This commit is contained in:
Mitchell Hashimoto
2024-03-10 20:57:44 -07:00
parent 4254dc9eef
commit 361fdd2179

View File

@ -2754,8 +2754,7 @@ fn dragLeftClickSingle(
// If we were selecting, and we switched directions, then we restart // If we were selecting, and we switched directions, then we restart
// calculations because it forces us to reconsider if the first cell is // calculations because it forces us to reconsider if the first cell is
// selected. // selected.
// TODO(paged-terminal) self.checkResetSelSwitch(drag_pin);
//self.checkResetSelSwitch(screen_point);
// Our logic for determining if the starting cell is selected: // Our logic for determining if the starting cell is selected:
// //
@ -2851,8 +2850,14 @@ fn dragLeftClickSingle(
// Resets the selection if we switched directions, depending on the select // Resets the selection if we switched directions, depending on the select
// mode. See dragLeftClickSingle for more details. // mode. See dragLeftClickSingle for more details.
fn checkResetSelSwitch(self: *Surface, screen_point: terminal.point.ScreenPoint) void { fn checkResetSelSwitch(
const sel = self.io.terminal.screen.selection orelse return; self: *Surface,
drag_pin: terminal.Pin,
) void {
const screen = &self.io.terminal.screen;
const sel = screen.selection orelse return;
const sel_start = sel.start();
const sel_end = sel.end();
var reset: bool = false; var reset: bool = false;
if (sel.rectangle) { if (sel.rectangle) {
@ -2860,26 +2865,27 @@ fn checkResetSelSwitch(self: *Surface, screen_point: terminal.point.ScreenPoint)
// the click point depending on the selection mode we're in, with // the click point depending on the selection mode we're in, with
// the exception of single-column selections, which we always reset // the exception of single-column selections, which we always reset
// on if we drift. // on if we drift.
if (sel.start.x == sel.end.x) { if (sel_start.x == sel_end.x) {
reset = screen_point.x != sel.start.x; reset = drag_pin.x != sel_start.x;
} else { } else {
reset = switch (sel.order()) { reset = switch (sel.order(screen)) {
.forward => screen_point.x < sel.start.x or screen_point.y < sel.start.y, .forward => drag_pin.x < sel_start.x or drag_pin.before(sel_start),
.reverse => screen_point.x > sel.start.x or screen_point.y > sel.start.y, .reverse => drag_pin.x > sel_start.x or sel_start.before(drag_pin),
.mirrored_forward => screen_point.x > sel.start.x or screen_point.y < sel.start.y, .mirrored_forward => drag_pin.x > sel_start.x or drag_pin.before(sel_start),
.mirrored_reverse => screen_point.x < sel.start.x or screen_point.y > sel.start.y, .mirrored_reverse => drag_pin.x < sel_start.x or sel_start.before(drag_pin),
}; };
} }
} else { } else {
// Normal select uses simpler logic that is just based on the // Normal select uses simpler logic that is just based on the
// selection start/end. // selection start/end.
reset = if (sel.end.before(sel.start)) reset = if (sel_end.before(sel_start))
sel.start.before(screen_point) sel_start.before(drag_pin)
else else
screen_point.before(sel.start); drag_pin.before(sel_start);
} }
if (reset) self.setSelection(null); // Nullifying a selection can't fail.
if (reset) self.setSelection(null) catch unreachable;
} }
// Handles how whether or not the drag screen point is before the click point. // Handles how whether or not the drag screen point is before the click point.