Skip to content

Commit 895d7d3

Browse files
committed
fix command append_mode_same_line
If the cursor was not at the end of the selection range, but the range end was a newline, `append_mode_same_line` would cause the cursor to jump to a wrong position. See #10576 (comment) for details.
1 parent 028522d commit 895d7d3

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

helix-term/src/commands.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3188,20 +3188,23 @@ fn append_mode_same_line(cx: &mut Context) {
31883188
let text = doc.text().slice(..);
31893189

31903190
let selection = doc.selection(view.id).clone().transform(|range| {
3191-
let pos = range.cursor(text);
3192-
let line = text.char_to_line(pos);
3193-
let end_char_index = line_end_char_index(&text, line);
3194-
let pos_is_at_end_of_line = pos == end_char_index;
3195-
3196-
if pos_is_at_end_of_line {
3197-
range
3191+
let forward_range = range.with_direction(Direction::Forward);
3192+
let range_end = forward_range.cursor(text);
3193+
let line = text.char_to_line(range_end);
3194+
let line_end_char_index = line_end_char_index(&text, line);
3195+
let is_at_end_of_line = range_end == line_end_char_index;
3196+
3197+
let new_range_end = if is_at_end_of_line {
3198+
range_end
31983199
} else {
3199-
Range::new(
3200-
range.from(),
3201-
graphemes::next_grapheme_boundary(doc.text().slice(..), range.to()),
3202-
)
3203-
}
3200+
range.to()
3201+
};
3202+
Range::new(
3203+
range.from(),
3204+
graphemes::next_grapheme_boundary(doc.text().slice(..), new_range_end),
3205+
)
32043206
});
3207+
32053208
doc.set_selection(view.id, selection);
32063209
}
32073210

0 commit comments

Comments
 (0)