Fix triple clicking empty line and dragging (#5068)

Fixes core issue #4957. Adds a bool to `SelectLine` allowing the
`selectLine` function to select lines that are empty. When starting a
triple selection on an empty line the initial `selectLine` returns null
because we don't see any characters, in this case we rerun `selectLine`
but short circuit with the `allow_empty_lines`. We need to run
`selectLine` with out allowing empty lines once because if there are
characters on the line we don't want to select empty space.
This commit is contained in:
Mitchell Hashimoto
2025-01-20 10:37:54 -08:00
committed by GitHub

View File

@ -3563,22 +3563,21 @@ fn dragLeftClickTriple(
const screen = &self.io.terminal.screen; const screen = &self.io.terminal.screen;
const click_pin = self.mouse.left_click_pin.?.*; const click_pin = self.mouse.left_click_pin.?.*;
// Get the word under our current point. If there isn't a word, do nothing. // Get the line selection under our current drag point. If there isn't a
const word = screen.selectLine(.{ .pin = drag_pin }) orelse return; // line, do nothing.
const line = screen.selectLine(.{ .pin = drag_pin }) orelse return;
// Get our selection to grow it. If we don't have a selection, start it now. // Get the selection under our click point. We first try to trim
// We may not have a selection if we started our dbl-click in an area // whitespace if we've selected a word. But if no word exists then
// that had no data, then we dragged our mouse into an area with data. // we select the blank line.
var sel = screen.selectLine(.{ .pin = click_pin }) orelse { const sel_ = screen.selectLine(.{ .pin = click_pin }) orelse
try self.setSelection(word); screen.selectLine(.{ .pin = click_pin, .whitespace = null });
return;
};
// Grow our selection var sel = sel_ orelse return;
if (drag_pin.before(click_pin)) { if (drag_pin.before(click_pin)) {
sel.startPtr().* = word.start(); sel.startPtr().* = line.start();
} else { } else {
sel.endPtr().* = word.end(); sel.endPtr().* = line.end();
} }
try self.setSelection(sel); try self.setSelection(sel);
} }