From 9d6ea773e9468578ec049f2b24df2fd133f14b53 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Thu, 23 Jan 2025 17:32:55 -0500 Subject: [PATCH] prompt: Cap anchor to line length in cursor calculation This prevents a panic when using `C-w` on a long single-word prompt line for example. Connects #12036 --- helix-term/src/ui/prompt.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs index 5f9745be3..03adeb05b 100644 --- a/helix-term/src/ui/prompt.rs +++ b/helix-term/src/ui/prompt.rs @@ -734,8 +734,9 @@ impl Component for Prompt { .clip_left(self.prompt.len() as u16) .clip_right(if self.prompt.len() > 0 { 0 } else { 2 }); + let anchor = self.anchor.min(self.line.len().saturating_sub(1)); let mut col = area.left() as usize - + UnicodeWidthStr::width(&self.line[self.anchor..self.cursor.max(self.anchor)]); + + UnicodeWidthStr::width(&self.line[anchor..self.cursor.max(anchor)]); // ensure the cursor does not go beyond elipses if self.truncate_end && self.cursor - self.anchor >= self.line_area.width as usize {