aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJames Campos <james.r.campos@gmail.com>2021-03-26 22:13:10 -0700
committerJames Campos <james.r.campos@gmail.com>2021-03-26 22:13:10 -0700
commite89d24bfc8242e43992eb420ffe468092e381a62 (patch)
treec8103748ffd29e1cf4c6ddf79c4ca0fa4195633c /src
parent48786a80c2f96afd9a935688015ffd5da1cbfeb0 (diff)
downloadbk-e89d24bfc8242e43992eb420ffe468092e381a62.tar.gz
internal
Diffstat (limited to 'src')
-rw-r--r--src/view.rs33
1 files changed, 11 insertions, 22 deletions
diff --git a/src/view.rs b/src/view.rs
index e06c1ff..4a5cb73 100644
--- a/src/view.rs
+++ b/src/view.rs
@@ -338,29 +338,23 @@ impl View for Page {
let text_end = c.lines[last_line - 1].1;
let mut base = {
- let start = match c
- .attrs
- .binary_search_by_key(&text_start, |&x| x.0)
- {
+ let start = match c.attrs.binary_search_by_key(&text_start, |&x| x.0) {
Ok(n) => n,
Err(n) => n - 1,
};
- let attr = c.attrs[start].2;
+ let map = c.attrs[start].2;
let mut head = Vec::new();
- if attr.has(Attribute::Bold) {
- head.push((text_start, Attribute::Bold));
- }
- if attr.has(Attribute::Italic) {
- head.push((text_start, Attribute::Italic));
- }
- if attr.has(Attribute::Underlined) {
- head.push((text_start, Attribute::Underlined));
+ let list = [Attribute::Bold, Attribute::Italic, Attribute::Underlined];
+ for attr in std::array::IntoIter::new(list) {
+ if map.has(attr) {
+ head.push((text_start, attr));
+ }
}
let tail = c.attrs[start + 1..]
- .iter()
- .take_while(|x| x.0 < text_end)
- .map(|x| (x.0, x.1));
+ .iter()
+ .take_while(|x| x.0 <= text_end)
+ .map(|x| (x.0, x.1));
head.into_iter().chain(tail).peekable()
};
@@ -399,18 +393,13 @@ impl View for Page {
}
let mut attrs = attrs.into_iter().peekable();
- // itertools: peeking take while
let mut buf = Vec::with_capacity(last_line - bk.line);
for &(mut pos, line_end) in &c.lines[bk.line..last_line] {
let mut s = String::new();
- while let Some(&(attr_pos, attr)) = attrs.peek() {
- if attr_pos > line_end {
- break;
- }
+ while let Some((attr_pos, attr)) = attrs.next_if(|a| a.0 <= line_end) {
s.push_str(&c.text[pos..attr_pos]);
s.push_str(&attr.to_string());
pos = attr_pos;
- attrs.next();
}
s.push_str(&c.text[pos..line_end]);
buf.push(s);