aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/commands.rs
diff options
context:
space:
mode:
authorSkyler Hawthorne2022-03-17 03:34:21 +0000
committerSkyler Hawthorne2022-06-19 03:54:03 +0000
commit0f3c10a021bbe79e20bde1f55b87465edeec476d (patch)
treea2d54e96885b5761e806eddd9bd8206071d15e8c /helix-term/src/commands.rs
parent502d3290fb88d8a871b0824adc7987a98104933d (diff)
Fix initial selection of Document in new view
When a new View of a Document is created, a default cursor of 0, 0 is created, and it does not get normalized to a single width cursor until at least one movement of the cursor happens. This appears to have no practical negative effect that I could find, but it makes tests difficult to work with, since the initial selection is not what you expect it to be. This changes the initial selection of a new View to be the width of the first grapheme in the text.
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r--helix-term/src/commands.rs17
1 files changed, 12 insertions, 5 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index c9c8e6a9..6b01cbe3 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -2094,10 +2094,17 @@ fn insert_mode(cx: &mut Context) {
let (view, doc) = current!(cx.editor);
enter_insert_mode(doc);
- let selection = doc
- .selection(view.id)
- .clone()
- .transform(|range| Range::new(range.to(), range.from()));
+ log::trace!(
+ "entering insert mode with sel: {:?}, text: {:?}",
+ doc.selection(view.id),
+ doc.text().to_string()
+ );
+
+ let selection = doc.selection(view.id).clone().transform(|range| {
+ let new_range = Range::new(range.to(), range.from());
+ new_range
+ });
+
doc.set_selection(view.id, selection);
}
@@ -2444,8 +2451,8 @@ fn normal_mode(cx: &mut Context) {
graphemes::prev_grapheme_boundary(text, range.to()),
)
});
- doc.set_selection(view.id, selection);
+ doc.set_selection(view.id, selection);
doc.restore_cursor = false;
}
}