mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Implement search shortcuts
This commit is contained in:
parent
566855ed55
commit
5e05b450a3
@ -10,6 +10,7 @@ from complete import create_search_bar
|
||||
from dom import add_extra_css, build_rule, svgicon
|
||||
from read_book.globals import ui_operations
|
||||
from read_book.resources import text_from_serialized_html
|
||||
from read_book.shortcuts import shortcut_for_key_event
|
||||
|
||||
CLASS_NAME = 'book-search-container'
|
||||
|
||||
@ -40,12 +41,22 @@ class SearchOverlay:
|
||||
create_search_bar(self.find_next, 'search-in-book', placeholder=_('Search') + '…', button=next_button, associated_widgets=[prev_button, close_button]),
|
||||
'\xa0', next_button, '\xa0', prev_button, '\xa0', close_button
|
||||
))
|
||||
c.firstChild.addEventListener('keydown', self.onkeydown)
|
||||
c.firstChild.addEventListener('keydown', self.onkeydown, {'passive': False})
|
||||
|
||||
def onkeydown(self, event):
|
||||
if event.key is 'Escape' or event.key is 'Esc':
|
||||
self.hide()
|
||||
event.preventDefault(), event.stopPropagation()
|
||||
return
|
||||
sc_name = shortcut_for_key_event(event, self.view.keyboard_shortcut_map)
|
||||
if sc_name is 'next_match':
|
||||
self.find_next()
|
||||
event.preventDefault(), event.stopPropagation()
|
||||
return
|
||||
if sc_name is 'previous_match':
|
||||
self.find_previous()
|
||||
event.preventDefault(), event.stopPropagation()
|
||||
return
|
||||
|
||||
@property
|
||||
def container(self):
|
||||
|
@ -157,6 +157,24 @@ SHORTCUTS = {
|
||||
_('Show/hide Table of Contents'),
|
||||
),
|
||||
|
||||
'start_search': desc(
|
||||
v"['/', 'Ctrl+f']",
|
||||
'ui',
|
||||
_('Start search'),
|
||||
),
|
||||
|
||||
'next_match': desc(
|
||||
v"['F3']",
|
||||
'ui',
|
||||
_('Find next'),
|
||||
),
|
||||
|
||||
'previous_match': desc(
|
||||
v"['Shift+F3']",
|
||||
'ui',
|
||||
_('Find previous'),
|
||||
),
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -24,6 +24,7 @@ from read_book.prefs.font_size import change_font_size_by
|
||||
from read_book.prefs.head_foot import render_head_foot
|
||||
from read_book.resources import load_resources
|
||||
from read_book.search import SearchOverlay, find_in_spine
|
||||
from read_book.shortcuts import create_shortcut_map
|
||||
from read_book.timers import Timers
|
||||
from read_book.toc import get_current_toc_nodes, update_visible_toc_nodes
|
||||
from read_book.touch import set_left_margin_handler, set_right_margin_handler
|
||||
@ -106,6 +107,7 @@ class View:
|
||||
self.show_chrome_counter = 0
|
||||
self.clock_timer_id = 0
|
||||
sd = get_session_data()
|
||||
self.keyboard_shortcut_map = create_shortcut_map(sd.get('keyboard_shortcuts'))
|
||||
left_margin = E.div(svgicon('caret-left'), style='width:{}px;'.format(sd.get('margin_left', 20)), class_='book-side-margin', id='book-left-margin', onclick=self.left_margin_clicked)
|
||||
set_left_margin_handler(left_margin)
|
||||
right_margin = E.div(svgicon('caret-right'), style='width:{}px;'.format(sd.get('margin_right', 20)), class_='book-side-margin', id='book-right-margin', onclick=self.right_margin_clicked)
|
||||
@ -229,6 +231,12 @@ class View:
|
||||
ui_operations.toggle_inspector()
|
||||
elif data.name is 'toggle_lookup':
|
||||
ui_operations.toggle_lookup()
|
||||
elif data.name is 'start_search':
|
||||
self.show_search()
|
||||
elif data.name is 'next_match':
|
||||
self.search_overlay.find_next()
|
||||
elif data.name is 'previous_match':
|
||||
self.search_overlay.find_previous()
|
||||
|
||||
def on_selection_change(self, data):
|
||||
self.currently_showing.selected_text = data.text
|
||||
@ -429,6 +437,9 @@ class View:
|
||||
sd.set('controls_help_shown_count', c + 1)
|
||||
|
||||
def redisplay_book(self):
|
||||
# redisplay_book() is called when settings are changed
|
||||
sd = get_session_data()
|
||||
self.keyboard_shortcut_map = create_shortcut_map(sd.get('keyboard_shortcuts'))
|
||||
self.display_book(self.book)
|
||||
|
||||
def iframe_settings(self, name):
|
||||
|
Loading…
x
Reference in New Issue
Block a user