Fix regression when selection start is deleted

Ranges with start > end are invalid; we crash with "slice index starts at
10 but ends at 0".
This commit is contained in:
Johannes Altmanninger 2024-03-30 09:22:28 +01:00
parent b535213ac0
commit a29cc8f169
2 changed files with 11 additions and 1 deletions

View file

@ -1380,7 +1380,7 @@ impl ReaderData {
let selection_color =
HighlightSpec::with_fg_bg(HighlightRole::selection, HighlightRole::selection);
let end = std::cmp::min(selection.stop, colors.len());
for color in &mut colors[selection.start..end] {
for color in &mut colors[selection.start.min(end)..end] {
*color = selection_color;
}
}

View file

@ -19,3 +19,13 @@ isolated-tmux capture-pane -p
# CHECK: prompt 0> begin
# CHECK: echo 123
# CHECK: end
# regression test
isolated-tmux send-keys C-c # not sure why we need to wait after this
tmux-sleep
isolated-tmux send-keys 'bind S begin-selection' Enter C-l
tmux-sleep
isolated-tmux send-keys 'echo one two threeS' C-u C-y
tmux-sleep
isolated-tmux capture-pane -p
# CHECK: prompt 1> echo one two three