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

This commit is contained in:
chrox
2015-02-03 12:10:25 +08:00
parent 5545474d4e
commit 1894e71b07

View File

@@ -242,14 +242,19 @@ function ReaderToc:updateCurrentNode()
end
end
function ReaderToc:expandCurrentNode()
local current_node_index = self:getTocIndexByPage(self.pageno)
if current_node_index then
for i = current_node_index - 1, 1, -1 do
if self.toc[i+1].depth > self.toc[i].depth then
self:expandToc(i)
break
function ReaderToc:expandParentNode(index)
if index then
local nodes_to_expand = {}
local depth = self.toc[index].depth
for i = index - 1, 1, -1 do
if depth > self.toc[i].depth then
depth = self.toc[i].depth
table.insert(nodes_to_expand, i)
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
@@ -349,7 +354,7 @@ function ReaderToc:onShowToc()
self.toc_menu = toc_menu
-- auto expand the parent node of current page
self:expandCurrentNode()
self:expandParentNode(self:getTocIndexByPage(self.pageno))
UIManager:show(menu_container)
@@ -372,6 +377,9 @@ function ReaderToc:expandToc(index)
break
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
local v = self.toc[i]
if v.depth == cur_depth + 1 then