diff --git a/frontend/apps/reader/modules/readertoc.lua b/frontend/apps/reader/modules/readertoc.lua index fb368843b..edd9c0904 100644 --- a/frontend/apps/reader/modules/readertoc.lua +++ b/frontend/apps/reader/modules/readertoc.lua @@ -111,7 +111,7 @@ function ReaderToc:_getChapterPagesLeft(pageno,pages) j=0 if #self.toc > 0 then - for i=1, #self.toc do + for i = 1, #self.toc do v = self.toc[i] if v.page > pageno then j = v.page @@ -119,13 +119,45 @@ function ReaderToc:_getChapterPagesLeft(pageno,pages) end end end - if j==0 then - return pages-pageno + if j == 0 then + if pages > 0 then + return pages-pageno + else + return "" + end else return j-pageno-1 end end +function ReaderToc:_getChapterPagesDone(pageno) + if not self.toc then + -- build toc when needed. + self:fillToc() + end + + -- no table of content + if #self.toc == 0 then + return "" + end + + j=0 + if #self.toc > 0 then + for i = 1, #self.toc do + v = self.toc[i] + if v.page >= pageno then + break + end + j = v.page + end + end + if j < 2 then + return "" + else + return j-pageno + end +end + function ReaderToc:onShowToc() if not self.toc then