Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextEdit: fix crash when hitting SHIFT + TAB around non-ASCII text #3984

Merged
merged 19 commits into from
Mar 12, 2024
Merged
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions crates/egui/src/widgets/text_edit/text_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment on lines +92 to +97
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Iteration over chars two times can be time consuming for a long text. It is better to do that only once

Copy link
Contributor Author

@rustbasic rustbasic Feb 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be, you right.
However, it only works when we press SHIFT + TAB, so we don't need to change it.

.take(TAB_SIZE)
.all(|c| c == ' ')
{
Expand Down
Loading