Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Fix crash when the length of a line is greater than 1024 chars (#11536)
张小白1b292d2fb387
diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rsindex e2326a24563..57c84b62b5b 100644--- a/crates/editor/src/element.rs+++ b/crates/editor/src/element.rs@@ -4495,20 +4495,26 @@ fn layout_line() -> Result<ShapedLine> {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,