Skip to content

Commit

Permalink
Add AttrsList::spans_iter and use it in Buffer::append
Browse files Browse the repository at this point in the history
  • Loading branch information
UkoeHB authored and jackpot51 committed Sep 1, 2024
1 parent caa214a commit c751217
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,12 @@ impl AttrsList {

/// Get the current attribute spans
pub fn spans(&self) -> Vec<(&Range<usize>, &AttrsOwned)> {
self.spans.iter().collect()
self.spans_iter().collect()
}

/// Get an iterator over the current attribute spans
pub fn spans_iter(&self) -> impl Iterator<Item = (&Range<usize>, &AttrsOwned)> + '_ {
self.spans.iter()
}

/// Clear the current attribute spans
Expand Down
2 changes: 1 addition & 1 deletion src/buffer_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit c751217

Please sign in to comment.