Use range positions to determine insert_newline motion (#9448)

* use anchor and head positions to determine motion

* use range cursor to decide extending or shifting

* add condition to cursor moving back on normal
This commit is contained in:
Waleed Dahshan 2024-01-30 08:58:33 +11:00 committed by GitHub
parent 87a720c3a1
commit cf4492174d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 5 deletions

View file

@ -3651,7 +3651,7 @@ pub mod insert {
(pos, pos, local_offs)
};
let new_range = if doc.restore_cursor {
let new_range = if range.cursor(text) > range.anchor {
// when appending, extend the range by local_offs
Range::new(
range.anchor + global_offs,

View file

@ -1990,10 +1990,12 @@ impl Editor {
if doc.restore_cursor {
let text = doc.text().slice(..);
let selection = doc.selection(view.id).clone().transform(|range| {
Range::new(
range.from(),
graphemes::prev_grapheme_boundary(text, range.to()),
)
let mut head = range.to();
if range.head > range.anchor {
head = graphemes::prev_grapheme_boundary(text, head);
}
Range::new(range.from(), head)
});
doc.set_selection(view.id, selection);