Skip to content

Commit

Permalink
check selection's visible width when copying on mouse click (#2711)
Browse files Browse the repository at this point in the history
* 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.

* use range.fragment to simplify getting the primary selection width
  • Loading branch information
the-mikedavis authored Jun 24, 2022
1 parent 886cff3 commit d948ace
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1127,9 +1127,14 @@ impl EditorView {
}

let (view, doc) = current!(cxt.editor);
let range = doc.selection(view.id).primary();

if range.to() - range.from() <= 1 {
if doc
.selection(view.id)
.primary()
.fragment(doc.text().slice(..))
.width()
<= 1
{
return EventResult::Ignored(None);
}

Expand Down

0 comments on commit d948ace

Please sign in to comment.