check selection's visible width when copying on mouse click (#2711)
* 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
commitd948ace67b10f162fd00106b9be2c1c680f33861
authorMichael Davis <mcarsondavis@gmail.com>
dateFri 24 Jun 2022, 08:58 (4 years ago)
parent886cff3
helix-term/src/ui/editor.rs+7−2
@@ -1127,9 +1127,14 @@ impl EditorView {
11271127 }
11281128
11291129 let (view, doc) = current!(cxt.editor);
1130− let range = doc.selection(view.id).primary();
11311130
1132− if range.to() - range.from() <= 1 {
1131+ if doc
1132+ .selection(view.id)
1133+ .primary()
1134+ .fragment(doc.text().slice(..))
1135+ .width()
1136+ <= 1
1137+ {
11331138 return EventResult::Ignored(None);
11341139 }
11351140