diff --git a/frontend/apps/reader/modules/readerpaging.lua b/frontend/apps/reader/modules/readerpaging.lua index 076326920..ba7fccd6c 100644 --- a/frontend/apps/reader/modules/readerpaging.lua +++ b/frontend/apps/reader/modules/readerpaging.lua @@ -306,6 +306,7 @@ function ReaderPaging:enterSkimMode() zoom_mode = self.view.zoom_mode, current_page = self.current_page, location = self:getBookLocation(), + visible_area = self.visible_area, } self.view.document.configurable.text_wrap = 0 self.view.page_scroll = false @@ -325,6 +326,7 @@ function ReaderPaging:exitSkimMode() self.current_page = 0 -- do not emit extra PageUpdate event self:onRestoreBookLocation(self.skim_backup.location) end + self.visible_area = self.skim_backup.visible_area self.skim_backup = nil end end @@ -560,14 +562,17 @@ function ReaderPaging:onGotoPercent(percent) return true end -function ReaderPaging:onGotoViewRel(diff) +function ReaderPaging:onGotoViewRel(diff, no_page_turn) + -- ReaderSearch calls with no_page_turn = true. + -- In that case, don't turn page if it would happen, and return ret=nil. + local ret if self.view.page_scroll then - self:onScrollPageRel(diff) + ret = self:onScrollPageRel(diff, no_page_turn) else - self:onGotoPageRel(diff) + ret = self:onGotoPageRel(diff, no_page_turn) end self:setPagePosition(self:getTopPage(), self:getTopPosition()) - return true + return ret end function ReaderPaging:onGotoPosRel(diff) @@ -890,7 +895,8 @@ function ReaderPaging:onScrollPanRel(diff) return true end -function ReaderPaging:onScrollPageRel(page_diff) +function ReaderPaging:onScrollPageRel(page_diff, no_page_turn) + if no_page_turn then return end -- see ReaderPaging:onGotoViewRel if page_diff == 0 then return true end if page_diff > 1 or page_diff < -1 then -- More than 1 page, don't bother with how far we've scrolled. @@ -934,7 +940,7 @@ function ReaderPaging:onScrollPageRel(page_diff) return true end -function ReaderPaging:onGotoPageRel(diff) +function ReaderPaging:onGotoPageRel(diff, no_page_turn) logger.dbg("goto relative page:", diff) local new_va = self.visible_area:copy() local x_pan_off, y_pan_off = 0, 0 @@ -1019,10 +1025,12 @@ function ReaderPaging:onGotoPageRel(diff) new_page = self.current_page + diff end if new_page > self.number_of_pages then + if no_page_turn then return true end self.ui:handleEvent(Event:new("EndOfBook")) goto_end(y) goto_end(x) elseif new_page > 0 then + if no_page_turn then return true end -- Be sure that the new and old view areas are reset so that no value is carried over to next page. -- Without this, we would have panned_y = new_va.y - old_va.y > 0, and panned_y will be added to the next page's y direction. -- This occurs when the current page has a y > 0 position (for example, a cropped page) and can fit the whole page height, @@ -1044,6 +1052,7 @@ function ReaderPaging:onGotoPageRel(diff) local prev_page = self.current_page -- Handle cases when the view area gets out of page boundaries + local would_turn_page if not self.page_area:contains(new_va) then if not at_end(x) then goto_end(x) @@ -1053,11 +1062,12 @@ function ReaderPaging:onGotoPageRel(diff) if not at_end(y) then goto_end(y) else - goto_next_page() + would_turn_page = goto_next_page() end end end end + if no_page_turn and would_turn_page then return end -- see ReaderPaging:onGotoViewRel if self.current_page == prev_page then -- Page number haven't changed when panning inside a page, diff --git a/frontend/apps/reader/modules/readersearch.lua b/frontend/apps/reader/modules/readersearch.lua index 7692e6955..ab320b6c3 100644 --- a/frontend/apps/reader/modules/readersearch.lua +++ b/frontend/apps/reader/modules/readersearch.lua @@ -17,7 +17,7 @@ local C_ = _.pgettext local Screen = Device.screen local T = require("ffi/util").template -local DGENERIC_ICON_SIZE = G_defaults:readSetting("DGENERIC_ICON_SIZE") +local icon_size = Screen:scaleBySize(0.8 * G_defaults:readSetting("DGENERIC_ICON_SIZE")) -- square icons local ReaderSearch = InputContainer:extend{ direction = 0, -- 0 for search forward, 1 for search backward @@ -183,6 +183,17 @@ function ReaderSearch:addToMainMenu(menu_items) } UIManager:show(widget) end, + separator = true, + }, + { + text = _("Zoom fixed layout documents to full page"), + help_text = _("On searching, temporarily zoom the document to full page."), + checked_func = function() + return G_reader_settings:isTrue("fulltext_search_zoom_to_page") + end, + callback = function() + G_reader_settings:flipNilOrFalse("fulltext_search_zoom_to_page") + end, }, }, } @@ -323,6 +334,7 @@ function ReaderSearch:onShowFulltextSearchInput(search_string) end function ReaderSearch:onShowSearchDialog(text, direction, regex, case_insensitive) + local zoom_to_page = G_reader_settings:isTrue("fulltext_search_zoom_to_page") local neglect_current_location = false local current_page @@ -334,6 +346,10 @@ function ReaderSearch:onShowSearchDialog(text, direction, regex, case_insensitiv end local do_search = function(search_func, search_term, param) return function() + if self.ui.paging and zoom_to_page and not self.skim_mode then + self.skim_mode = true + self.ui.paging:enterSkimMode() -- "page" view + end local no_results = true -- for notification local res = search_func(self, search_term, param, regex, case_insensitive) if res then @@ -429,14 +445,13 @@ function ReaderSearch:onShowSearchDialog(text, direction, regex, case_insensitiv end end if no_results then - local notification_text - if self._expect_back_results then - notification_text = _("No results on preceding pages") - else - notification_text = _("No results on following pages") + if self.skim_mode then + self.skim_mode = nil + self.ui.paging:exitSkimMode() end UIManager:show(Notification:new{ - text = notification_text, + text = self._expect_back_results and _("No results on preceding pages") + or _("No results on following pages"), }) end end @@ -480,12 +495,16 @@ function ReaderSearch:onShowSearchDialog(text, direction, regex, case_insensitiv { text = backward_text, vsync = true, - callback = search(self.searchNext, text, 1), + callback = function() + if self.ui.rolling or zoom_to_page or not self.ui.paging:onGotoViewRel(-1, true) then + search(self.searchNext, text, 1)() + end + end, }, { icon = "appbar.search", - icon_width = Screen:scaleBySize(DGENERIC_ICON_SIZE * 0.8), - icon_height = Screen:scaleBySize(DGENERIC_ICON_SIZE * 0.8), + icon_width = icon_size, + icon_height = icon_size, callback = function() self.search_dialog:onClose() self:onShowFulltextSearchInput() @@ -494,7 +513,11 @@ function ReaderSearch:onShowSearchDialog(text, direction, regex, case_insensitiv { text = forward_text, vsync = true, - callback = search(self.searchNext, text, 0), + callback = function() + if self.ui.rolling or zoom_to_page or not self.ui.paging:onGotoViewRel(1, true) then + search(self.searchNext, text, 0)() + end + end, }, { text = from_end_text, @@ -504,9 +527,7 @@ function ReaderSearch:onShowSearchDialog(text, direction, regex, case_insensitiv } }, tap_close_callback = function() - logger.dbg("highlight clear") - self.ui.highlight:clear() - UIManager:setDirty(self.dialog, "ui") + self:restorePageView() end, } if regex and isSlowRegex(text) then @@ -670,19 +691,7 @@ function ReaderSearch:onShowFindAllResults(not_cached) title_bar_left_icon = "appbar.menu", onLeftButtonTap = function() self:showAllResultsMenuDialog() end, onMenuChoice = function(_menu_self, item) - if self.ui.rolling then - self.ui.link:addCurrentLocationToStack() - self.ui.rolling:onGotoXPointer(item.start, item.start) -- show target line marker - self.ui.document:getTextFromXPointers(item.start, item["end"], true) -- highlight - else - local page = item.start - local boxes = {} - for i, box in ipairs(item.boxes) do - boxes[i] = self.ui.document:nativeToPageRectTransform(page, box) - end - self.ui.link:onGotoLink({ page = page - 1 }) - self.view.highlight.temp[page] = boxes - end + self:gotoResultsItem(item.idx) end, onMenuHold = function(_menu_self, item) local text = T(_("Page: %1"), item.mandatory) .. "\n" @@ -796,6 +805,98 @@ function ReaderSearch:showAllResultsMenuDialog() UIManager:show(button_dialog) end +function ReaderSearch:gotoResultsItem(index) + local item = self.result_menu.item_table[index] + if self.ui.rolling then + self.ui.link:addCurrentLocationToStack() + self.ui.rolling:onGotoXPointer(item.start, item.start) -- show target line marker + self.ui.document:getTextFromXPointers(item.start, item["end"], true) -- highlight + else + if not self.skim_mode then + self.skim_mode = true + self.ui.paging:enterSkimMode() -- "page" view + end + local page = item.start + local boxes = {} + for i, box in ipairs(item.boxes) do + boxes[i] = self.ui.document:nativeToPageRectTransform(page, box) + end + self.ui.link:onGotoLink({ page = page - 1 }) + self.view.highlight.temp[page] = boxes + end + + local chevron_left = "chevron.left" + local chevron_right = "chevron.right" + if BD.mirroredUILayout() then + chevron_left, chevron_right = chevron_right, chevron_left + end + local dialog + dialog = ButtonDialog:new{ + buttons = { + { + { + text = "\u{21BA}", -- Anticlockwise Open Circle Arrow + callback = function() + dialog:onClose() + self:onGoToStartPage() + end, + }, + { + icon = chevron_left, + icon_width = icon_size, + icon_height = icon_size, + enabled = index > 1, + callback = function() + UIManager:close(dialog) + self:gotoResultsItem(index - 1) + end, + hold_callback = function() + UIManager:close(dialog) + self:gotoResultsItem(1) + end, + }, + { + text = T("%1 / %2", index, #self.result_menu.item_table), + font_bold = false, + width = math.floor(math.min(Screen:getWidth(), Screen:getHeight()) * 0.25), + callback = function() + dialog:onClose() + self.findall_results_item_index = index + self:onShowFindAllResults() + end, + }, + { + icon = chevron_right, + icon_width = icon_size, + icon_height = icon_size, + enabled = index < #self.result_menu.item_table, + callback = function() + UIManager:close(dialog) + self:gotoResultsItem(index + 1) + end, + hold_callback = function() + UIManager:close(dialog) + self:gotoResultsItem(#self.result_menu.item_table) + end, + }, + { + icon = "appbar.search", + icon_width = icon_size, + icon_height = icon_size, + callback = function() + dialog:onClose() + self:onShowFulltextSearchInput() + end, + }, + } + }, + tap_close_callback = function() + self:restorePageView() + end, + } + UIManager:show(dialog) +end + function ReaderSearch:onGoToStartPage() if self.start_page then if self.ui.rolling then @@ -806,4 +907,14 @@ function ReaderSearch:onGoToStartPage() end end +function ReaderSearch:restorePageView() + logger.dbg("highlight clear") + self.ui.highlight:clear() + if self.skim_mode then + self.skim_mode = nil + self.ui.paging:exitSkimMode() + end + UIManager:setDirty(self.dialog, "ui") +end + return ReaderSearch