From c50f978efff7b52bd858dc130c9e5cb7a7881360 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Mon, 24 May 2021 16:51:32 +0200 Subject: [PATCH] Change `BufferView::layout_lines` to use `highlighted_chunks_at` --- zed/src/editor/buffer_view.rs | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/zed/src/editor/buffer_view.rs b/zed/src/editor/buffer_view.rs index 4c2469095f1cff79151f941b1cbb472c0d70dc8e..d7a4be9aa37d9ffbb0e6c358e2d62fece20c408e 100644 --- a/zed/src/editor/buffer_view.rs +++ b/zed/src/editor/buffer_view.rs @@ -2141,26 +2141,27 @@ impl BufferView { let mut layouts = Vec::with_capacity(rows.len()); let mut line = String::new(); + let mut styles = Vec::new(); let mut row = rows.start; let snapshot = self.display_map.snapshot(ctx); - let chunks = snapshot.chunks_at(DisplayPoint::new(rows.start, 0), ctx); - for (chunk_row, chunk_line) in chunks - .chain(Some("\n")) - .flat_map(|chunk| chunk.split("\n").enumerate()) - { - if chunk_row > 0 { - layouts.push(layout_cache.layout_str( - &line, - font_size, - &[(line.len(), font_id, ColorU::black())], - )); - line.clear(); - row += 1; - if row == rows.end { - break; + let chunks = snapshot.highlighted_chunks_at(rows.start, ctx); + 'outer: for (chunk, capture_ix) in chunks.chain(Some(("\n", None))) { + for (ix, chunk_line) in chunk.split('\n').enumerate() { + if ix > 0 { + layouts.push(layout_cache.layout_str(&line, font_size, &styles)); + line.clear(); + styles.clear(); + row += 1; + if row == rows.end { + break 'outer; + } + } + + if !chunk_line.is_empty() { + line.push_str(chunk_line); + styles.push((chunk_line.len(), font_id, ColorU::black())); } } - line.push_str(chunk_line); } Ok(layouts)