diff --git a/src/pyj/read_book/iframe.pyj b/src/pyj/read_book/iframe.pyj index ac9233418a..6d56b8fd4f 100644 --- a/src/pyj/read_book/iframe.pyj +++ b/src/pyj/read_book/iframe.pyj @@ -18,7 +18,8 @@ from read_book.paged_mode import ( layout as paged_layout, scroll_to_fraction as paged_scroll_to_fraction, onwheel as paged_onwheel, onkeydown as paged_onkeydown, scroll_to_elem, jump_to_cfi as paged_jump_to_cfi, handle_gesture as paged_handle_gesture, - scroll_by_page as paged_scroll_by_page, anchor_funcs as paged_anchor_funcs + scroll_by_page as paged_scroll_by_page, anchor_funcs as paged_anchor_funcs, + snap_to_selection ) from read_book.settings import apply_settings, opts from read_book.touch import create_handlers as create_touch_handlers @@ -48,6 +49,7 @@ class IframeBoss: 'change_font_size': self.change_font_size, 'change_color_scheme': self.change_color_scheme, 'gesture_from_margin': self.gesture_from_margin, + 'find': self.find, } self.last_window_ypos = 0 @@ -272,6 +274,13 @@ class IframeBoss: if elem: scroll_to_elem(elem) + def find(self, data): + if window.find(data.text, False, data.backwards): + if current_layout_mode() is not 'flow': + snap_to_selection() + else: + self.send_message('find_in_spine', text=data.text, backwards=data.backwards) + def init(): script = document.getElementById('bootstrap') script.parentNode.removeChild(script) # free up some memory diff --git a/src/pyj/read_book/search.pyj b/src/pyj/read_book/search.pyj index d22f674799..cbbc84fa59 100644 --- a/src/pyj/read_book/search.pyj +++ b/src/pyj/read_book/search.pyj @@ -13,7 +13,7 @@ CLASS_NAME = 'book-search-container' add_extra_css(def(): sel = '.' + CLASS_NAME - style = build_rule(sel, text_align='right') + style = build_rule(sel, text_align='right', user_select='none') sel += ' > div ' style += build_rule(sel, display='inline-flex', pointer_events='auto', background_color=get_color('window-background'), padding='1ex') return style @@ -50,6 +50,10 @@ class SearchOverlay: def container(self): return document.getElementById('book-search-overlay') + @property + def search_text(self): + return self.container.querySelector('input').value + def hide(self): self.container.style.display = 'none' @@ -58,8 +62,13 @@ class SearchOverlay: c.style.display = 'block' c.querySelector('input').focus() + def find(self, text, backwards): + if not text: + return + self.view.find(text, backwards) + def find_next(self): - pass + self.find(self.search_text, False) def find_previous(self): - pass + self.find(self.search_text, True) diff --git a/src/pyj/read_book/view.pyj b/src/pyj/read_book/view.pyj index 374e3b9420..b8e81e1fce 100644 --- a/src/pyj/read_book/view.pyj +++ b/src/pyj/read_book/view.pyj @@ -94,6 +94,7 @@ class View: 'content_loaded': self.on_content_loaded, 'show_chrome': self.show_chrome, 'bump_font_size': self.bump_font_size, + 'find_in_spine': self.on_find_in_spine, } self.currently_showing = {} @@ -119,6 +120,12 @@ class View: def forward_gesture(self, gesture): self.send_message('gesture_from_margin', gesture=gesture) + def find(self, text, backwards): + self.send_message('find', text=text, backwards=backwards) + + def on_find_in_spine(self, data): + pass + def bump_font_size(self, data): delta = 2 if data.increase else -2 change_font_size_by(delta)