Back/forward keyboard shortcuts

This commit is contained in:
Kovid Goyal 2019-08-25 18:01:43 +05:30
parent e1ce4976e6
commit a4f1b54421
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 25 additions and 0 deletions

View File

@ -256,6 +256,8 @@ class WebPage(QWebEnginePage):
def acceptNavigationRequest(self, url, req_type, is_main_frame):
if req_type == self.NavigationTypeReload:
return True
if req_type == self.NavigationTypeBackForward:
return True
if url.scheme() in (FAKE_PROTOCOL, 'data'):
return True
open_url(url)

View File

@ -353,6 +353,8 @@ class IframeBoss:
if sc_name:
if self.handle_navigation_shortcut(sc_name, evt):
evt.preventDefault()
else:
self.send_message('handle_shortcut', name=sc_name)
def oncontextmenu(self, evt):
if self.content_ready:

View File

@ -138,6 +138,20 @@ SHORTCUTS = {
_('Scroll forwards by screen-fulls'),
),
'back': desc(
v"['Alt+ArrowLeft', 'Shift+ArrowLeft']",
'scroll',
_('Back'),
),
'forward': desc(
v"['Alt+ArrowRight', 'Shift+ArrowRight']",
'scroll',
_('Forward'),
),
}

View File

@ -150,6 +150,7 @@ class View:
'print': self.on_print,
'human_scroll': self.on_human_scroll,
'selectionchange': self.on_selection_change,
'handle_shortcut': self.on_handle_shortcut,
}
entry_point = None if runtime.is_standalone_viewer else 'read_book.iframe'
self.iframe_wrapper = IframeWrapper(handlers, document.getElementById(iframe_id), entry_point, _('Bootstrapping book reader...'), runtime.FAKE_PROTOCOL, runtime.FAKE_HOST)
@ -215,6 +216,12 @@ class View:
amt_scrolled = data.scrolled_by_frac * length
self.timers.on_human_scroll(amt_scrolled)
def on_handle_shortcut(self, data):
if data.name is 'back':
window.history.back()
elif data.name is 'forward':
window.history.forward()
def on_selection_change(self, data):
self.currently_showing.selected_text = data.text
if ui_operations.selection_changed: