From 5e7f554cc3a24a7341ca15522d75af0e296cbfa0 Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Fri, 8 Mar 2024 12:39:56 -0700 Subject: [PATCH] Fix panic in layout_line when Y coordinate is too high (cherry-pick #9052) (#9075) Cherry-picked Fix panic in layout_line when Y coordinate is too high (#9052) Release Notes: - N/A Co-authored-by: Conrad Irwin --- crates/gpui/src/text_system/line_layout.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/gpui/src/text_system/line_layout.rs b/crates/gpui/src/text_system/line_layout.rs index ac27705801523dd89c30bc5273c1aaf59057d312..ced49068c84aeb8faeac1cda7fe934876bfbdfb3 100644 --- a/crates/gpui/src/text_system/line_layout.rs +++ b/crates/gpui/src/text_system/line_layout.rs @@ -247,10 +247,11 @@ impl WrappedLineLayout { let wrapped_line_ix = (position.y / line_height) as usize; let wrapped_line_start_x = if wrapped_line_ix > 0 { - let wrap_boundary_ix = wrapped_line_ix - 1; - let wrap_boundary = self.wrap_boundaries[wrap_boundary_ix]; - let run = &self.unwrapped_layout.runs[wrap_boundary.run_ix]; - run.glyphs[wrap_boundary.glyph_ix].position.x + let Some(line_start_boundary) = self.wrap_boundaries.get(wrapped_line_ix - 1) else { + return None; + }; + let run = &self.unwrapped_layout.runs[line_start_boundary.run_ix]; + run.glyphs[line_start_boundary.glyph_ix].position.x } else { Pixels::ZERO };