mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 07:46:12 +03:00
add and use flag for selecting empty lines in the selectLine function
This commit is contained in:
@ -3563,22 +3563,23 @@ fn dragLeftClickTriple(
|
||||
const screen = &self.io.terminal.screen;
|
||||
const click_pin = self.mouse.left_click_pin.?.*;
|
||||
|
||||
// Get the word under our current point. If there isn't a word, do nothing.
|
||||
const word = screen.selectLine(.{ .pin = drag_pin }) orelse return;
|
||||
// Get the line selection under our current drag point. If there isn't a 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.
|
||||
// We may not have a selection if we started our dbl-click in an area
|
||||
// that had no data, then we dragged our mouse into an area with data.
|
||||
var sel = screen.selectLine(.{ .pin = click_pin }) orelse {
|
||||
try self.setSelection(word);
|
||||
return;
|
||||
};
|
||||
// get the selection under our click point.
|
||||
var sel_ = screen.selectLine(.{ .pin = click_pin });
|
||||
|
||||
// Grow our selection
|
||||
// We may not have a selection if we started our triple-click in an area
|
||||
// that had no data, in this case recall selectLine with allow_empty_lines.
|
||||
if (sel_ == null) {
|
||||
sel_ = screen.selectLine(.{ .pin = click_pin, .allow_empty_lines = true });
|
||||
}
|
||||
|
||||
var sel = sel_ orelse return;
|
||||
if (drag_pin.before(click_pin)) {
|
||||
sel.startPtr().* = word.start();
|
||||
sel.startPtr().* = line.start();
|
||||
} else {
|
||||
sel.endPtr().* = word.end();
|
||||
sel.endPtr().* = line.end();
|
||||
}
|
||||
try self.setSelection(sel);
|
||||
}
|
||||
|
@ -2215,6 +2215,7 @@ pub const SelectLine = struct {
|
||||
/// state changing a boundary. State changing is ANY state
|
||||
/// change.
|
||||
semantic_prompt_boundary: bool = true,
|
||||
allow_empty_lines: bool = false,
|
||||
};
|
||||
|
||||
/// Select the line under the given point. This will select across soft-wrapped
|
||||
@ -2292,6 +2293,11 @@ pub fn selectLine(self: *const Screen, opts: SelectLine) ?Selection {
|
||||
return null;
|
||||
};
|
||||
|
||||
// If we allow empty lines, we don't need to do any further checks.
|
||||
if (opts.allow_empty_lines) {
|
||||
return Selection.init(start_pin, end_pin, false);
|
||||
}
|
||||
|
||||
// Go forward from the start to find the first non-whitespace character.
|
||||
const start: Pin = start: {
|
||||
const whitespace = opts.whitespace orelse break :start start_pin;
|
||||
|
Reference in New Issue
Block a user