From a35f1b7d26d4be0f3beb21393910e3e11923d962 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 24 Dec 2016 11:05:13 +0530 Subject: [PATCH] More work on toc highlighting --- src/pyj/read_book/toc.pyj | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/pyj/read_book/toc.pyj b/src/pyj/read_book/toc.pyj index a053616707..a9dce0864d 100644 --- a/src/pyj/read_book/toc.pyj +++ b/src/pyj/read_book/toc.pyj @@ -16,7 +16,14 @@ def update_visible_toc_nodes(visible_anchors): update_visible_toc_nodes.data = {} -def get_highlighted_toc_nodes(toc, parent_map, id_map): +def iter_toc_nodes(node, callback): + if callback(node): + return + for child in node.children: + if callback(child): + return + +def get_highlighted_toc_nodes(toc, spine, parent_map, id_map): data = update_visible_toc_nodes.data ans = {} if data.has_visible: @@ -25,7 +32,14 @@ def get_highlighted_toc_nodes(toc, parent_map, id_map): if data.before: ans[data.before] = True else: - pass # TODO: implement this + nodes_before = v'[]' + iter_toc_nodes(toc, def(node): + if node.dest is current_spine_item(): + return True + nodes_before.push(node) + ) + if nodes_before.length: + ans[nodes_before[-1].id] = True for node_id in Object.keys(ans): pid = parent_map[node_id] while pid: