Skip to content

Commit

Permalink
Use range positions to determine insert_newline motion (helix-editor#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
wmstack authored and Schuyler Mortimer committed Jul 10, 2024
1 parent be1c0a3 commit a36f21f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3655,7 +3655,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,
Expand Down
10 changes: 6 additions & 4 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a36f21f

Please sign in to comment.