More work on viewer search

This commit is contained in:
Kovid Goyal 2017-01-06 13:58:33 +05:30
parent 55a06967f7
commit 10648d3d00
3 changed files with 29 additions and 4 deletions

View File

@ -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

View File

@ -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)

View File

@ -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)