readerrolling(fix): do not emit PageUpdate event until document is ready

pull/2279/head
Qingping Hou 8 years ago
parent c998120a78
commit abbb72b6d3

@ -97,7 +97,7 @@ function ReaderFont:onReadSettings(config)
or DCREREADER_CONFIG_DEFAULT_FONT_GAMMA
self.ui.document:setGammaIndex(self.gamma_index)
-- Dirty hack: we have to add folloing call in order to set
-- Dirty hack: we have to add following call in order to set
-- m_is_rendered(member of LVDocView) to true. Otherwise position inside
-- document will be reset to 0 on first view render.
-- So far, I don't know why this call will alter the value of m_is_rendered.

@ -174,17 +174,17 @@ function ReaderRolling:onReadSettings(config)
local last_xp = config:readSetting("last_xpointer")
local last_per = config:readSetting("last_percent")
if last_xp then
table.insert(self.ui.postInitCallback, function()
self.xpointer = last_xp
self.xpointer = last_xp
self.onReaderReady = function()
self:_gotoXPointer(self.xpointer)
-- we have to do a real jump in self.ui.document._document to
-- update status information in CREngine.
self.ui.document:gotoXPointer(self.xpointer)
end)
end
-- we read last_percent just for backward compatibility
-- FIXME: remove this branch with migration script
elseif last_per then
table.insert(self.ui.postInitCallback, function()
self.onReaderReady = function()
self:_gotoPercent(last_per)
-- _gotoPercent calls _gotoPos, which only updates self.current_pos
-- and self.view.
@ -198,12 +198,14 @@ function ReaderRolling:onReadSettings(config)
Event:new("PageUpdate", self.ui.document:getCurrentPage()))
end
self.xpointer = self.ui.document:getXPointer()
end)
end
else
if self.view.view_mode == "page" then
self.ui:handleEvent(Event:new("PageUpdate", 1))
self.onReaderReady = function()
self.xpointer = self.ui.document:getXPointer()
if self.view.view_mode == "page" then
self.ui:handleEvent(Event:new("PageUpdate", 1))
end
end
self.xpointer = self.ui.document:getXPointer()
end
self.show_overlap_enable = config:readSetting("show_overlap_enable")
if self.show_overlap_enable == nil then

@ -39,6 +39,7 @@ describe("ReaderLink module", function()
}
readerui:handleEvent(Event:new("SetScrollMode", true))
readerui.paging:onGotoPage(1)
assert.is.same(1, readerui.paging.current_page)
readerui.link:onTap(nil, {pos = {x = 250, y = 534}})
UIManager:run()
-- its really hard to get the exact page number in scroll mode
@ -79,6 +80,7 @@ describe("ReaderLink module", function()
}
readerui:handleEvent(Event:new("SetScrollMode", true))
readerui.paging:onGotoPage(1)
assert.is.same(1, readerui.paging.current_page)
readerui.link:onTap(nil, {pos = {x = 250, y = 534}})
UIManager:run()
assert.truthy(readerui.paging.current_page == 21
@ -87,7 +89,7 @@ describe("ReaderLink module", function()
assert.is.same(1, readerui.paging.current_page)
end)
it("should be able to go back after link jump in pdf in scroll mode", function()
it("should be able to go back to the same position after link jump in pdf scroll mode", function()
UIManager:quit()
local expected_page_states = {
{
@ -123,6 +125,7 @@ describe("ReaderLink module", function()
}
-- disable footer
G_reader_settings:saveSetting("reader_footer_mode", 0)
require("docsettings"):open(sample_pdf):purge()
local readerui = ReaderUI:new{
document = DocumentRegistry:openDocument(sample_pdf),
}

@ -182,4 +182,20 @@ describe("Readerrolling module", function()
end
end)
end)
describe("test initialization", function()
it("should emit PageUpdate event after book is rendered", function()
local ReaderView = require("apps/reader/modules/readerview")
local saved_handler = ReaderView.onPageUpdate
ReaderView.onPageUpdate = function(_self)
assert.are.same(7, _self.ui.document:getPageCount())
end
local test_book = "spec/front/unit/data/sample.txt"
require("docsettings"):open(test_book):purge()
ReaderUI:new{
document = DocumentRegistry:openDocument(test_book),
}
ReaderView.onPageUpdate = saved_handler
end)
end)
end)

Loading…
Cancel
Save