From a29cc8f1695478422885418c7610de6f36668168 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sat, 30 Mar 2024 09:22:28 +0100 Subject: [PATCH] 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". --- src/reader.rs | 2 +- tests/checks/tmux-bind.fish | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/reader.rs b/src/reader.rs index 6caa42e74..1322008f8 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -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; } } diff --git a/tests/checks/tmux-bind.fish b/tests/checks/tmux-bind.fish index 1cb412954..54c8f4f6f 100644 --- a/tests/checks/tmux-bind.fish +++ b/tests/checks/tmux-bind.fish @@ -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