Make Shift+LeftClick extend existing selection
This matches cmd.exe and other programs (notepad, office, etc) behavior: First click selects "start", then Shift+click selects "end". They form a range. This is particularly useful to select a large range of text, since the user can release the left button, then operate on the scroll bar without worrying about messing up text selection. It gets a bit more complicated with the POSIX "mouse grabbed" situation. When the mouse is grabbed, it's usually a full-screen ncurses-like application. Selection mostly likely only makes sense within a single screen. So Shift + LeftClick just works as starting a selection in this case (otherwise it'll be hard to clear a selection).
This commit is contained in:
1 parent
511fc55b10
commit
70e9c7cb16
2 files changed
+23
-3
No files matched your search
@@ -26,6 +26,10 @@ impl Selection {
|
||||
self.range = None;
|
||||
self.start = Some(start);
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.range.is_none()
|
||||
}
|
||||
}
|
||||
|
||||
/// The x,y coordinates of either the start or end of a selection region
|
||||
|
||||
@@ -2512,6 +2512,7 @@ impl TermWindow {
|
||||
}
|
||||
|
||||
// Left single click to initiate a selection drag
|
||||
// Shift+Left click to extend a selection
|
||||
(
|
||||
WMEK::Press(MousePress::Left),
|
||||
Some(LastMouseClick {
|
||||
@@ -2520,9 +2521,24 @@ impl TermWindow {
|
||||
..
|
||||
}),
|
||||
) => {
|
||||
self.selection(tab.tab_id())
|
||||
.begin(SelectionCoordinate { x, y: stable_row });
|
||||
self.window.as_ref().unwrap().set_clipboard(String::new());
|
||||
// If the mouse is grabbed, do not use Shfit+Left to
|
||||
// extend a selection, since otherwise it's hard to
|
||||
// clear a selection.
|
||||
if tab.is_mouse_grabbed()
|
||||
|| !event.modifiers.contains(Modifiers::SHIFT)
|
||||
|| self.selection(tab.tab_id()).is_empty()
|
||||
{
|
||||
// Initiate a selection
|
||||
self.selection(tab.tab_id())
|
||||
.begin(SelectionCoordinate { x, y: stable_row });
|
||||
self.window.as_ref().unwrap().set_clipboard(String::new());
|
||||
} else {
|
||||
// Extend selection
|
||||
let end = SelectionCoordinate { x, y: stable_row };
|
||||
let mut selection = self.selection(tab.tab_id());
|
||||
selection.range = selection.range.map(|sel| sel.extend(end));
|
||||
context.invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
// Release button to finish a selection
|
||||
|
||||
Reference in new issue
Block a user