From 59b44cb27da33f3dc1aaab94cdbe500b99bb4c7d Mon Sep 17 00:00:00 2001 From: James Campos Date: Sat, 11 Jul 2020 18:32:49 -0700 Subject: attributes --- src/main.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index f07ba1e..d977b12 100644 --- a/src/main.rs +++ b/src/main.rs @@ -309,15 +309,16 @@ fn render_page(bk: &Bk, offset: usize) -> Vec { let c = bk.chap(); let line_end = min(bk.line + bk.rows - offset, bk.chap().lines.len()); + // TODO support inline tags (strong) let attrs = { let text_start = c.lines[bk.line].0; let text_end = c.lines[line_end - 1].1; let mut search = Vec::new(); - if bk.query != "" { + let qlen = bk.query.len(); + if qlen > 0 { for (pos, _) in c.text[text_start..text_end].match_indices(&bk.query) { - search.push((text_start + pos, Attribute::Reverse)); - search.push((text_start + pos + bk.query.len(), Attribute::Reset)); + search.push(text_start + pos); } } let mut search_iter = search.into_iter(); @@ -343,8 +344,12 @@ fn render_page(bk: &Bk, offset: usize) -> Vec { match (sn, an) { (None, None) => panic!("does this happen?"), (Some(s), None) => { - merged.push(s); - merged.extend(search_iter); + merged.push((s, Attribute::Reverse)); + merged.push((s + qlen, Attribute::Reset)); + for s in search_iter { + merged.push((s, Attribute::Reverse)); + merged.push((s + qlen, Attribute::Reset)); + } break; } (None, Some(&a)) => { @@ -353,8 +358,11 @@ fn render_page(bk: &Bk, offset: usize) -> Vec { break; } (Some(s), Some(&a)) => { - if s.0 < a.0 { - merged.push(s); + if s < a.0 { + merged.push((s, Attribute::Reverse)); + merged.push((s + qlen, Attribute::Reset)); + // this match arm is inside a header tag + merged.push((s + qlen, Attribute::Bold)); sn = search_iter.next(); } else { merged.push(a); -- cgit v1.2.3