From 1b292d2fb387252554249bcb9df011f5cbc528bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=B0=8F=E7=99=BD?= <364772080@qq.com> Date: Thu, 9 May 2024 07:08:39 +0800 Subject: [PATCH] Fix crash when the length of a line is greater than 1024 chars (#11536) Close #11518 Release Notes: - N/A --- crates/editor/src/element.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index e2326a24563129b49bc562a499085652645b0abe..57c84b62b5b82beb012e094c556cc5c990fdc64d 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -4495,20 +4495,26 @@ fn layout_line( ) -> Result { let mut line = snapshot.line(row); - if line.len() > MAX_LINE_LEN { - let mut len = MAX_LINE_LEN; - while !line.is_char_boundary(len) { - len -= 1; - } + let len = { + let line_len = line.len(); + if line_len > MAX_LINE_LEN { + let mut len = MAX_LINE_LEN; + while !line.is_char_boundary(len) { + len -= 1; + } - line.truncate(len); - } + line.truncate(len); + len + } else { + line_len + } + }; cx.text_system().shape_line( line.into(), style.text.font_size.to_pixels(cx.rem_size()), &[TextRun { - len: snapshot.line_len(row) as usize, + len, font: style.text.font(), color: Hsla::default(), background_color: None,