Merge pull request #1576 from mitchellh/undefined

core: remove undefined access on variable
This commit is contained in:
Mitchell Hashimoto
2024-03-10 17:48:23 -07:00
committed by GitHub

View File

@ -2799,35 +2799,34 @@ 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(self: *Surface, screen_point: terminal.point.ScreenPoint) void {
var reset: bool = undefined; const sel = self.io.terminal.screen.selection orelse return;
if (self.io.terminal.screen.selection) |sel| {
if (sel.rectangle) { var reset: bool = false;
// When we're in rectangle mode, we reset the selection relative to if (sel.rectangle) {
// the click point depending on the selection mode we're in, with // When we're in rectangle mode, we reset the selection relative to
// the exception of single-column selections, which we always reset // the click point depending on the selection mode we're in, with
// on if we drift. // the exception of single-column selections, which we always reset
if (sel.start.x == sel.end.x) { // on if we drift.
reset = screen_point.x != sel.start.x; if (sel.start.x == sel.end.x) {
} else { reset = screen_point.x != sel.start.x;
reset = switch (sel.order()) {
.forward => screen_point.x < sel.start.x or screen_point.y < sel.start.y,
.reverse => screen_point.x > sel.start.x or screen_point.y > sel.start.y,
.mirrored_forward => screen_point.x > sel.start.x or screen_point.y < sel.start.y,
.mirrored_reverse => screen_point.x < sel.start.x or screen_point.y > sel.start.y,
};
}
} else { } else {
// Normal select uses simpler logic that is just based on the reset = switch (sel.order()) {
// selection start/end. .forward => screen_point.x < sel.start.x or screen_point.y < sel.start.y,
reset = if (sel.end.before(sel.start)) .reverse => screen_point.x > sel.start.x or screen_point.y > sel.start.y,
sel.start.before(screen_point) .mirrored_forward => screen_point.x > sel.start.x or screen_point.y < sel.start.y,
else .mirrored_reverse => screen_point.x < sel.start.x or screen_point.y > sel.start.y,
screen_point.before(sel.start); };
} }
} else {
// Normal select uses simpler logic that is just based on the
// selection start/end.
reset = if (sel.end.before(sel.start))
sel.start.before(screen_point)
else
screen_point.before(sel.start);
} }
if (reset) if (reset) self.setSelection(null);
self.setSelection(null);
} }
// 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.