From 850a77776038ced2a72440abfa1e3337cc7d76cd Mon Sep 17 00:00:00 2001 From: Tigran Aivazian Date: Thu, 27 Sep 2012 13:10:28 +0100 Subject: [PATCH] On pressing Back crereader loses last position This fix makes the behaviour of Back command handler in crereader identical with that in unireader, i.e. the last position is saved in Jump History when pressing Back, so you can return to it by pressing Shift-Back enough times. Also, with this change we would need to handle the need for redrawing the current page because the :addJump() method can force the call to fillToc() (if TOC is not already present) and this will display "Retrieving TOC..." message which will need clearing away. --- crereader.lua | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/crereader.lua b/crereader.lua index 90756ea1c..52a8587ff 100644 --- a/crereader.lua +++ b/crereader.lua @@ -636,12 +636,29 @@ function CREReader:adjustCreReaderCommands() self.commands:add(KEY_BACK, nil, "Back", "go backward in jump history", function(self) - local prev_jump_no = self.jump_history.cur - 1 + local prev_jump_no = 0 + local need_refresh = false + if self.jump_history.cur > #self.jump_history then + -- addJump() will cause a "Retrieving TOC..." msg, so we'll + -- need to redraw the page after our own + -- ifo msg "Already first jump!" below + if not self.toc then need_refresh = true end + + -- if cur points to head, put current page in history + self:addJump(self.doc:getXPointer()) + prev_jump_no = self.jump_history.cur - 2 + else + prev_jump_no = self.jump_history.cur - 1 + end + if prev_jump_no >= 1 then self.jump_history.cur = prev_jump_no self:goto(self.jump_history[prev_jump_no].page, true, "xpointer") else showInfoMsgWithDelay("Already first jump!", 2000, 1) + if need_refresh then + self:redrawCurrentPage() + end end end )