Skip to content

Commit

Permalink
prompt: Cap anchor to line length in cursor calculation
Browse files Browse the repository at this point in the history
This prevents a panic when using `C-w` on a long single-word prompt line
for example.

Connects helix-editor#12036
  • Loading branch information
the-mikedavis committed Jan 23, 2025
1 parent 6b044ae commit 9d6ea77
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion helix-term/src/ui/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 9d6ea77

Please sign in to comment.