diff --git a/src/app/browser/window/tab/item/page/content/text/search.rs b/src/app/browser/window/tab/item/page/content/text/search.rs index db00b21e..5dd7d332 100644 --- a/src/app/browser/window/tab/item/page/content/text/search.rs +++ b/src/app/browser/window/tab/item/page/content/text/search.rs @@ -28,8 +28,8 @@ impl Search { let close = close::new(); let input = Rc::new(Input::new()); let match_case = match_case::new(); - let navigation = Rc::new(Navigation::new()); let tag = Rc::new(Tag::new(text_buffer.tag_table())); + let navigation = Rc::new(Navigation::new(text_buffer.clone(), tag.current.clone())); // Init main container let g_box = Box::builder() diff --git a/src/app/browser/window/tab/item/page/content/text/search/navigation.rs b/src/app/browser/window/tab/item/page/content/text/search/navigation.rs index 99fa5031..632882f3 100644 --- a/src/app/browser/window/tab/item/page/content/text/search/navigation.rs +++ b/src/app/browser/window/tab/item/page/content/text/search/navigation.rs @@ -4,7 +4,10 @@ mod forward; use back::Back; use forward::Forward; -use gtk::{prelude::BoxExt, Box, Orientation, TextIter}; +use gtk::{ + prelude::{BoxExt, TextBufferExt}, + Box, Orientation, TextBuffer, TextIter, TextTag, +}; use std::{ cell::{Cell, RefCell}, rc::Rc, @@ -18,13 +21,15 @@ pub struct Navigation { pub g_box: Box, index: Rc>, matches: Rc>>, + text_buffer: TextBuffer, + current_tag: TextTag, } impl Navigation { // Constructors /// Create new `Self` - pub fn new() -> Self { + pub fn new(text_buffer: TextBuffer, current_tag: TextTag) -> Self { // Init shared matches holder let index = Rc::new(Cell::new(0)); let matches = Rc::new(RefCell::new(Vec::new())); @@ -51,6 +56,8 @@ impl Navigation { g_box, index, matches, + text_buffer, + current_tag, } } @@ -67,9 +74,16 @@ impl Navigation { } pub fn back(&self) -> Option<(TextIter, TextIter)> { + self.text_buffer.remove_tag( + &self.current_tag, + &self.text_buffer.start_iter(), + &self.text_buffer.end_iter(), + ); + let index = self.index.take(); match self.matches.borrow().get(back(index)) { Some((start, end)) => { + self.text_buffer.apply_tag(&self.current_tag, &start, &end); self.index.replace(if index == 0 { len_to_index(self.matches.borrow().len()) } else { @@ -86,10 +100,17 @@ impl Navigation { } pub fn forward(&self) -> Option<(TextIter, TextIter)> { + self.text_buffer.remove_tag( + &self.current_tag, + &self.text_buffer.start_iter(), + &self.text_buffer.end_iter(), + ); + let index = self.index.take(); let next = forward(index); match self.matches.borrow().get(next) { Some((start, end)) => { + self.text_buffer.apply_tag(&self.current_tag, &start, &end); self.index.replace(next); Some((*start, *end)) } diff --git a/src/app/browser/window/tab/item/page/content/text/search/tag.rs b/src/app/browser/window/tab/item/page/content/text/search/tag.rs index babaa21f..55487d10 100644 --- a/src/app/browser/window/tab/item/page/content/text/search/tag.rs +++ b/src/app/browser/window/tab/item/page/content/text/search/tag.rs @@ -4,7 +4,7 @@ mod found; use gtk::{TextTag, TextTagTable}; pub struct Tag { - // pub current: TextTag, + pub current: TextTag, pub found: TextTag, } @@ -20,8 +20,6 @@ impl Tag { tag_table.add(¤t); tag_table.add(&found); - Self { - /*current,*/ found, - } + Self { current, found } } }