From f0190320333c8a8f5f5520833d754ada1ce0f529 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Tue, 12 Mar 2024 19:21:33 +0900 Subject: [PATCH] TextEdit: fix crash when hitting SHIFT + TAB around non-ASCII text (#3984) * Closes #3846 * Closes #3878 Dear emilk. Leaving aside other function, I think this is all you need to fix to patch the panic that occurs when Shift + TAB. Thank you, emilk. --- crates/egui/src/widgets/text_edit/text_buffer.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/egui/src/widgets/text_edit/text_buffer.rs b/crates/egui/src/widgets/text_edit/text_buffer.rs index f28878a1..e70ce695 100644 --- a/crates/egui/src/widgets/text_edit/text_buffer.rs +++ b/crates/egui/src/widgets/text_edit/text_buffer.rs @@ -89,10 +89,12 @@ pub trait TextBuffer { fn decrease_indentation(&mut self, ccursor: &mut CCursor) { let line_start = find_line_start(self.as_str(), *ccursor); - let remove_len = if self.as_str()[line_start.index..].starts_with('\t') { + let remove_len = if self.as_str().chars().nth(line_start.index) == Some('\t') { Some(1) - } else if self.as_str()[line_start.index..] + } else if self + .as_str() .chars() + .skip(line_start.index) .take(TAB_SIZE) .all(|c| c == ' ') {