diff options
author | Nathan Vegdahl | 2021-07-02 16:51:29 +0000 |
---|---|---|
committer | Nathan Vegdahl | 2021-07-02 16:51:29 +0000 |
commit | 28d2d6880462509f0d3131eb2eb928bb8859e058 (patch) | |
tree | 0c92886bd8d0fdfbbfb6f1472c50e775ca7463ed /helix-term | |
parent | 28627f97e9f0d7bc61368ecd221b1a0fc378f3b7 (diff) |
Make horizontal selection movement work properly.
Diffstat (limited to 'helix-term')
-rw-r--r-- | helix-term/src/commands.rs | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index e76962f0..5ab0926a 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -2193,7 +2193,25 @@ fn goto_mode(cx: &mut Context) { } fn select_mode(cx: &mut Context) { - doc_mut!(cx.editor).mode = Mode::Select; + let (view, doc) = current!(cx.editor); + + // Make sure all selections are at least 1-wide. + // (With the exception of being in an empty document, of course.) + doc.set_selection( + view.id, + doc.selection(view.id).clone().transform(|range| { + if range.is_empty() && range.head == doc.text().len_chars() { + Range::new( + graphemes::prev_grapheme_boundary(doc.text().slice(..), range.anchor), + range.head, + ) + } else { + range.min_width_1(doc.text().slice(..)) + } + }), + ); + + doc.mode = Mode::Select; } fn exit_select_mode(cx: &mut Context) { |