From 316e9c9a95f935509c48f63732b819a73a3817ea Mon Sep 17 00:00:00 2001 From: reuben olinsky Date: Thu, 28 Nov 2024 21:13:15 -0800 Subject: [PATCH] fix: correct handling of multi-byte chars in highlighter (#277) Use chars() instead of byte-slicing into the str while segmenting the input string into differently styled substrings. --- brush-interactive/src/reedline/highlighter.rs | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/brush-interactive/src/reedline/highlighter.rs b/brush-interactive/src/reedline/highlighter.rs index 85ef58dc..0361d6ce 100644 --- a/brush-interactive/src/reedline/highlighter.rs +++ b/brush-interactive/src/reedline/highlighter.rs @@ -1,3 +1,5 @@ +use std::str::Chars; + use super::refs; use nu_ansi_term::{Color, Style}; @@ -98,10 +100,10 @@ enum CommandType { struct StyledInputLine<'a> { shell: &'a brush_core::Shell, - input_line: &'a str, cursor: usize, styled: reedline::StyledText, - current_index: usize, + remaining_chars: Chars<'a>, + current_char_index: usize, next_missing_style: Option