From 3ad2a46ecf9542cccc19600d2ef8aa4161036710 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Mon, 26 Apr 2021 09:58:16 -0700 Subject: [PATCH] quickselect: avoid a panic when used with mux It looks like the mux search results include a trailing newline in some cases, which means that a match can wrap onto a second line. If that line is shorter than the label length, we could panic. This commit makes quickselect safer to use in this situation, but the real fix is with the mux search code. --- wezterm-gui/src/overlay/quickselect.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/wezterm-gui/src/overlay/quickselect.rs b/wezterm-gui/src/overlay/quickselect.rs index 7c109248c..5d9864eaf 100644 --- a/wezterm-gui/src/overlay/quickselect.rs +++ b/wezterm-gui/src/overlay/quickselect.rs @@ -450,7 +450,11 @@ impl Pane for QuickSelectOverlay { } } for (idx, c) in m.label.chars().enumerate() { - let mut attr = line.cells()[idx].attrs().clone(); + let mut attr = line + .cells() + .get(idx) + .map(|cell| cell.attrs().clone()) + .unwrap_or_else(|| CellAttributes::default()); attr.set_background(AnsiColor::Fuschia) .set_foreground(AnsiColor::Black) .set_reverse(false);