From 29034e56b47b7e259f9a18a01fcda8ff267fc2d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Fri, 27 Feb 2026 21:53:44 +0100 Subject: [PATCH] Avoid breakage in `LayoutRunIter::new` --- src/buffer.rs | 20 ++++++++++++-------- src/buffer_line.rs | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/buffer.rs b/src/buffer.rs index 0d3b493..fe16e26 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -108,7 +108,17 @@ pub struct LayoutRunIter<'b> { } impl<'b> LayoutRunIter<'b> { - pub const fn new( + pub const fn new(buffer: &'b Buffer) -> Self { + Self::from_lines( + buffer.lines.as_slice(), + buffer.height_opt, + buffer.metrics.line_height, + buffer.scroll.vertical, + buffer.scroll.line, + ) + } + + pub const fn from_lines( lines: &'b [BufferLine], height_opt: Option, line_height: f32, @@ -935,13 +945,7 @@ impl Buffer { /// Get the visible layout runs for rendering and other tasks pub fn layout_runs(&self) -> LayoutRunIter<'_> { - LayoutRunIter::new( - &self.lines, - self.height_opt, - self.metrics.line_height, - self.scroll.vertical, - self.scroll.line, - ) + LayoutRunIter::new(self) } /// Convert x, y position to Cursor (hit detection) diff --git a/src/buffer_line.rs b/src/buffer_line.rs index f4da9ee..0f3933c 100644 --- a/src/buffer_line.rs +++ b/src/buffer_line.rs @@ -279,7 +279,7 @@ impl BufferLine { /// Get the visible layout runs for rendering and other tasks pub fn layout_runs(&self, height_opt: Option, line_height: f32) -> LayoutRunIter<'_> { - LayoutRunIter::new(core::slice::from_ref(self), height_opt, line_height, 0.0, 0) + LayoutRunIter::from_lines(core::slice::from_ref(self), height_opt, line_height, 0.0, 0) } /// Get line metadata. This will be None if [`BufferLine::set_metadata`] has not been called