From 8bf153fbf151cff5966d3ff40ff00d98c01160fd Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Wed, 8 Jun 2022 11:18:26 -0500 Subject: [PATCH 1/2] check selection's visible width when copying on mouse click Mouse-click-up copies the selection produced by dragging. The event is ignored if the selection has a width of 1 though so you don't copy when clicking rather than dragging. The current check copies text when it has a visible width of 1 but is actually multiple characters in the rope like a CRLF line-ending. With this change we check the unicode width of the character(s) in the selection rather than the range length, so clicking on a CRLF line-ending does not copy. --- helix-term/src/ui/editor.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index f074d9f1c97f..57ed29c7ef6c 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -1094,7 +1094,13 @@ impl EditorView { let (view, doc) = current!(cxt.editor); let range = doc.selection(view.id).primary(); - if range.to() - range.from() <= 1 { + if doc + .text() + .slice(range.from()..range.to()) + .as_str() + .filter(|selection| selection.width() <= 1) + .is_some() + { return EventResult::Ignored(None); } From 1e3553965e58d2f289f532046fdc44e87970d7f6 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Tue, 21 Jun 2022 11:58:04 -0500 Subject: [PATCH 2/2] use range.fragment to simplify getting the primary selection width --- helix-term/src/ui/editor.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 57ed29c7ef6c..fbd9718805ce 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -1092,14 +1092,13 @@ impl EditorView { } let (view, doc) = current!(cxt.editor); - let range = doc.selection(view.id).primary(); if doc - .text() - .slice(range.from()..range.to()) - .as_str() - .filter(|selection| selection.width() <= 1) - .is_some() + .selection(view.id) + .primary() + .fragment(doc.text().slice(..)) + .width() + <= 1 { return EventResult::Ignored(None); }