Skip to content

Commit

Permalink
feat(commands): ensure the last character remains selected when press…
Browse files Browse the repository at this point in the history
…ing 'b' in select mode
  • Loading branch information
usagi-flow committed Feb 11, 2024
1 parent 7c752df commit 3009ad3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5622,12 +5622,16 @@ where
let text = doc.text().slice(..);

let selection = doc.selection(view.id).clone().transform(|range| {
let old_head = range.head;
let old_anchor = range.anchor;
let mut new_range = move_fn(text, range, count);

new_range.anchor = match cx.editor.mode {
// In select mode, use a sticky anchor and move the head only
Mode::Select => old_anchor,
// In select mode, use a sticky anchor and move the head only;
// keeping in mind that in select mode, with a single char selected,
// the anchor typically points *before* the character.
Mode::Select if new_range.head < old_head => old_head.max(old_anchor),
Mode::Select => old_head.min(old_anchor),
// When not in select mode, just move the cursor and do not select
_ => new_range.head,
};
Expand Down

0 comments on commit 3009ad3

Please sign in to comment.