mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Merge pull request #1413 from chrox/fix_toc_node_expand
don't expand toc node when it's parent node is collapsed
This commit is contained in:
@@ -59,11 +59,10 @@ function ReaderLink:addToMainMenu(tab_item_table)
|
||||
table.insert(tab_item_table.navi, {
|
||||
text = _("Follow links"),
|
||||
checked_func = function()
|
||||
return G_reader_settings:readSetting("follow_links") ~= false
|
||||
return G_reader_settings:readSetting("follow_links") == true
|
||||
end,
|
||||
callback = function()
|
||||
local follow_links = G_reader_settings:readSetting("follow_links")
|
||||
if follow_links == nil then follow_links = true end
|
||||
G_reader_settings:saveSetting("follow_links", not follow_links)
|
||||
end
|
||||
})
|
||||
@@ -77,7 +76,7 @@ function ReaderLink:onSetDimensions(dimen)
|
||||
end
|
||||
|
||||
function ReaderLink:onTap(arg, ges)
|
||||
if G_reader_settings:readSetting("follow_links") == false then return end
|
||||
if G_reader_settings:readSetting("follow_links") ~= true then return end
|
||||
if self.ui.document.info.has_pages then
|
||||
local pos = self.view:screenToPageTransform(ges.pos)
|
||||
if pos then
|
||||
|
||||
@@ -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
|
||||
@@ -298,8 +303,6 @@ function ReaderToc:onShowToc()
|
||||
end
|
||||
end
|
||||
|
||||
self:updateCurrentNode()
|
||||
|
||||
local button_size = self.expand_button:getSize()
|
||||
local toc_menu = Menu:new{
|
||||
title = _("Table of Contents"),
|
||||
@@ -348,8 +351,11 @@ function ReaderToc:onShowToc()
|
||||
|
||||
self.toc_menu = toc_menu
|
||||
|
||||
self:updateCurrentNode()
|
||||
-- auto expand the parent node of current page
|
||||
self:expandCurrentNode()
|
||||
self:expandParentNode(self:getTocIndexByPage(self.pageno))
|
||||
-- auto goto page of the current toc entry
|
||||
self.toc_menu:swithItemTable(nil, self.collapsed_toc, self.collapsed_toc.current or -1)
|
||||
|
||||
UIManager:show(menu_container)
|
||||
|
||||
@@ -372,6 +378,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
|
||||
|
||||
Reference in New Issue
Block a user