don't expand toc node when it's parent node is collapsed

pull/1413/head
chrox 9 years ago
parent 5545474d4e
commit 1894e71b07

@ -242,14 +242,19 @@ function ReaderToc:updateCurrentNode()
end end
end end
function ReaderToc:expandCurrentNode() function ReaderToc:expandParentNode(index)
local current_node_index = self:getTocIndexByPage(self.pageno) if index then
if current_node_index then local nodes_to_expand = {}
for i = current_node_index - 1, 1, -1 do local depth = self.toc[index].depth
if self.toc[i+1].depth > self.toc[i].depth then for i = index - 1, 1, -1 do
self:expandToc(i) if depth > self.toc[i].depth then
break depth = self.toc[i].depth
table.insert(nodes_to_expand, i)
end end
if depth == 1 then break end
end
for i = #nodes_to_expand, 1, -1 do
self:expandToc(nodes_to_expand[i])
end end
end end
end end
@ -349,7 +354,7 @@ function ReaderToc:onShowToc()
self.toc_menu = toc_menu self.toc_menu = toc_menu
-- auto expand the parent node of current page -- auto expand the parent node of current page
self:expandCurrentNode() self:expandParentNode(self:getTocIndexByPage(self.pageno))
UIManager:show(menu_container) UIManager:show(menu_container)
@ -372,6 +377,9 @@ function ReaderToc:expandToc(index)
break break
end end
end end
-- either the toc entry of index has no child nodes
-- or it's parent nodes are not expanded yet
if not collapsed_index then return end
for i = index + 1, #self.toc do for i = index + 1, #self.toc do
local v = self.toc[i] local v = self.toc[i]
if v.depth == cur_depth + 1 then if v.depth == cur_depth + 1 then

Loading…
Cancel
Save