aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Vegdahl2021-07-21 16:56:21 +0000
committerNathan Vegdahl2021-07-21 16:56:21 +0000
commit7d07704e6ff59ed2eee664bb14e9c6a8c42ee4fb (patch)
treee3ab6794d39674bcd875136994dee312a6ee2aeb
parent063aa9452d7c41e486a143b9f7e14fb5d14ad808 (diff)
Fix append mode not editing correctly.
This is currently a bit of a hack, and still doesn't behave quite how we probably want. Left a TODO.
-rw-r--r--helix-term/src/commands.rs21
1 files changed, 11 insertions, 10 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 475eccf2..35a67e36 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -1281,18 +1281,19 @@ fn append_mode(cx: &mut Context) {
let (view, doc) = current!(cx.editor);
enter_insert_mode(doc);
doc.restore_cursor = true;
+ let text = doc.text().slice(..);
- let selection = doc.selection(view.id).clone().transform(|range| {
- let to = if range.to() == range.from() {
- // For 1-width cursor semantics.
- graphemes::next_grapheme_boundary(doc.text().slice(..), range.to())
- } else {
- range.to()
- };
- Range::new(range.from(), to)
- });
+ // TODO: preserve selections, like in `Insert` mode. Probably we'll want
+ // an explicit separate `Append` mode or something similar, so that we
+ // don't change the selection at all, and instead just display and edit
+ // things differently.
+ let selection = doc
+ .selection(view.id)
+ .clone()
+ .min_width_1(text)
+ .transform(|range| Range::new(range.to(), range.to()));
- let end = doc.text().len_chars();
+ let end = text.len_chars();
if selection.iter().any(|range| range.head == end) {
let transaction = Transaction::change(