From 8169ad1f7aaa2d22d5b3b7129e2dcd130253a811 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 1 Jan 2017 21:05:49 +0530 Subject: [PATCH] Implement swipe up/down gestures tto move between sections --- src/pyj/read_book/goto.pyj | 7 +++++++ src/pyj/read_book/paged_mode.pyj | 2 +- src/pyj/read_book/view.pyj | 7 +++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/pyj/read_book/goto.pyj b/src/pyj/read_book/goto.pyj index 0aef3d0902..05d18e1c7c 100644 --- a/src/pyj/read_book/goto.pyj +++ b/src/pyj/read_book/goto.pyj @@ -25,6 +25,13 @@ def create_goto_list(onclick): return ans +def get_next_section(forward): + toc = current_book().manifest.toc + id_map = get_toc_maps(toc)[1] + before, after = get_border_nodes(toc, id_map) + return after if forward else before + + def create_goto_panel(book, container, onclick): panel = create_goto_list(onclick) set_css(container, display='flex', flex_direction='column') diff --git a/src/pyj/read_book/paged_mode.pyj b/src/pyj/read_book/paged_mode.pyj index 17083135d0..135f00b0be 100644 --- a/src/pyj/read_book/paged_mode.pyj +++ b/src/pyj/read_book/paged_mode.pyj @@ -505,7 +505,7 @@ def onkeydown(evt): def handle_gesture(gesture): if gesture.type is 'swipe': if gesture.axis is 'vertical': - pass # TODO: next/prev section + get_boss().send_message('next_section', forward=gesture.direction is 'up') else: if not gesture.active or gesture.is_held: scroll_by_page(gesture.direction is 'right', True) diff --git a/src/pyj/read_book/view.pyj b/src/pyj/read_book/view.pyj index 29629e09b8..290d59a607 100644 --- a/src/pyj/read_book/view.pyj +++ b/src/pyj/read_book/view.pyj @@ -15,6 +15,7 @@ from read_book.prefs.colors import resolve_color_scheme from read_book.prefs.font_size import change_font_size_by from read_book.touch import set_left_margin_handler, set_right_margin_handler from read_book.toc import update_visible_toc_nodes +from read_book.goto import get_next_section from book_list.theme import get_color from utils import parse_url_params, username_key @@ -82,6 +83,7 @@ class View: 'ready': self.on_iframe_ready, 'error': self.on_iframe_error, 'next_spine_item': self.on_next_spine_item, + 'next_section': self.on_next_section, 'goto_doc_boundary': self.goto_doc_boundary, 'scroll_to_anchor': self.on_scroll_to_anchor, 'update_cfi': self.on_update_cfi, @@ -310,6 +312,11 @@ class View: idx = max(0, min(spine.length - 1, idx + 1)) self.show_name(spine[idx], initial_position={'type':'frac', 'frac':0, 'replace_history':True}) + def on_next_section(self, data): + toc_node = get_next_section(data.forward) + if toc_node: + self.goto_named_destination(toc_node.dest, toc_node.frag) + def on_update_cfi(self, data): self.currently_showing.bookpos = data.cfi get_boss().push_state(replace=data.replace_history)