Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Maybe fix panic (#29352)

Conrad Irwin6692bd9f2bbb
diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs
index d919e24a845..0ecbdab07c7 100644
--- a/crates/editor/src/element.rs
+++ b/crates/editor/src/element.rs
@@ -2771,19 +2771,21 @@ impl EditorElement {
text_x + layout.width,
))
};
- x_position = if rows.contains(&align_to.row()) {
- x_and_width(&line_layouts[align_to.row().minus(rows.start) as usize])
- } else {
- x_and_width(&layout_line(
- align_to.row(),
- snapshot,
- &self.style,
- editor_width,
- is_row_soft_wrapped,
- window,
- cx,
- ))
- };
+ let line_ix = align_to.row().0.checked_sub(rows.start.0);
+ x_position =
+ if let Some(layout) = line_ix.and_then(|ix| line_layouts.get(ix as usize)) {
+ x_and_width(&layout)
+ } else {
+ x_and_width(&layout_line(
+ align_to.row(),
+ snapshot,
+ &self.style,
+ editor_width,
+ is_row_soft_wrapped,
+ window,
+ cx,
+ ))
+ };
let anchor_x = x_position.unwrap().0;