aboutsummaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
authorJonathan LEI2024-02-19 13:08:26 +0000
committerGitHub2024-02-19 13:08:26 +0000
commitcdef4f8a701f921c29fdfe66f104a2edac7fe05c (patch)
treeaa65defa1a20c7cf303b700b5d4c46906d823340 /helix-term
parent787cc36092a5d1a575697287d1d6ba08336a8a96 (diff)
Make mouse click extend selection in select mode (#5436)
* Make mouse click extend selection in select mode * chore: better readability with `Option::take()`
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/ui/editor.rs40
1 files changed, 28 insertions, 12 deletions
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs
index a87e6cbc..66f290a2 100644
--- a/helix-term/src/ui/editor.rs
+++ b/helix-term/src/ui/editor.rs
@@ -1088,6 +1088,15 @@ impl EditorView {
if modifiers == KeyModifiers::ALT {
let selection = doc.selection(view_id).clone();
doc.set_selection(view_id, selection.push(Range::point(pos)));
+ } else if editor.mode == Mode::Select {
+ // Discards non-primary selections for consistent UX with normal mode
+ let primary = doc.selection(view_id).primary().put_cursor(
+ doc.text().slice(..),
+ pos,
+ true,
+ );
+ editor.mouse_down_range = Some(primary);
+ doc.set_selection(view_id, Selection::single(primary.anchor, primary.head));
} else {
doc.set_selection(view_id, Selection::point(pos));
}
@@ -1171,19 +1180,26 @@ impl EditorView {
let (view, doc) = current!(cxt.editor);
- if doc
- .selection(view.id)
- .primary()
- .slice(doc.text().slice(..))
- .len_chars()
- <= 1
- {
- return EventResult::Ignored(None);
- }
-
- commands::MappableCommand::yank_main_selection_to_primary_clipboard.execute(cxt);
+ let should_yank = match cxt.editor.mouse_down_range.take() {
+ Some(down_range) => doc.selection(view.id).primary() != down_range,
+ None => {
+ // This should not happen under normal cases. We fall back to the original
+ // behavior of yanking on non-single-char selections.
+ doc.selection(view.id)
+ .primary()
+ .slice(doc.text().slice(..))
+ .len_chars()
+ > 1
+ }
+ };
- EventResult::Consumed(None)
+ if should_yank {
+ commands::MappableCommand::yank_main_selection_to_primary_clipboard
+ .execute(cxt);
+ EventResult::Consumed(None)
+ } else {
+ EventResult::Ignored(None)
+ }
}
MouseEventKind::Up(MouseButton::Right) => {