From c7512170201910cfb8a021f8d749c4125dfed18d Mon Sep 17 00:00:00 2001 From: koe Date: Fri, 30 Aug 2024 21:28:21 -0500 Subject: [PATCH] Add AttrsList::spans_iter and use it in Buffer::append --- src/attrs.rs | 7 ++++++- src/buffer_line.rs | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/attrs.rs b/src/attrs.rs index 1b17eed..046300c 100644 --- a/src/attrs.rs +++ b/src/attrs.rs @@ -306,7 +306,12 @@ impl AttrsList { /// Get the current attribute spans pub fn spans(&self) -> Vec<(&Range, &AttrsOwned)> { - self.spans.iter().collect() + self.spans_iter().collect() + } + + /// Get an iterator over the current attribute spans + pub fn spans_iter(&self) -> impl Iterator, &AttrsOwned)> + '_ { + self.spans.iter() } /// Clear the current attribute spans diff --git a/src/buffer_line.rs b/src/buffer_line.rs index 9eba6c7..4f1a195 100644 --- a/src/buffer_line.rs +++ b/src/buffer_line.rs @@ -144,7 +144,7 @@ impl BufferLine { .add_span(len..len + other.text().len(), other.attrs_list.defaults()); } - for (other_range, attrs) in other.attrs_list.spans() { + for (other_range, attrs) in other.attrs_list.spans_iter() { // Add previous attrs spans let range = other_range.start + len..other_range.end + len; self.attrs_list.add_span(range, attrs.as_attrs());