Fulltext search: action to show last findall results (#11388)

reviewable/pr11044/r7
hius07 3 months ago committed by GitHub
parent 82bf8bf379
commit 925aa728c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -133,6 +133,12 @@ function ReaderSearch:addToMainMenu(menu_items)
self:onShowFulltextSearchInput()
end,
}
menu_items.fulltext_search_findall_results = {
text = _("Last fulltext search results"),
callback = function()
self:onShowFindAllResults()
end,
}
end
-- if reverse ~= 0 search backwards
@ -142,6 +148,7 @@ function ReaderSearch:searchCallback(reverse)
-- search_text comes from our keyboard, and may contain multiple diacritics ordered
-- in any order: we'd rather have them normalized, and expect the book content to
-- be proper and normalized text.
self.ui.doc_settings:saveSetting("fulltext_search_last_search_text", search_text)
self.last_search_text = search_text -- if shown again, show it as it has been inputted
search_text = Utf8Proc.normalize_NFC(search_text)
self.use_regex = self.check_button_regex.checked
@ -178,7 +185,7 @@ function ReaderSearch:onShowFulltextSearchInput()
self.input_dialog = InputDialog:new{
title = _("Enter text to search for"),
width = math.floor(math.min(Screen:getWidth(), Screen:getHeight()) * 0.9),
input = self.last_search_text,
input = self.last_search_text or self.ui.doc_settings:readSetting("fulltext_search_last_search_text"),
buttons = {
{
{
@ -507,15 +514,22 @@ function ReaderSearch:findAllText(search_text)
UIManager:close(info)
self.last_search_hash = last_search_hash
self.findall_results = res
self.findall_results_item_index = nil
end
if self.findall_results then
self:showFindAllResults(not_cached)
self:onShowFindAllResults(not_cached)
else
UIManager:show(InfoMessage:new{ text = _("No results in the document") })
end
end
function ReaderSearch:showFindAllResults(not_cached)
function ReaderSearch:onShowFindAllResults(not_cached)
if not not_cached and self.findall_results == nil then
-- no cached results, show input dialog
self:onShowFulltextSearchInput()
return
end
if self.ui.rolling and not_cached then -- for ui.paging: items are built in KoptInterface:findAllText()
for _, item in ipairs(self.findall_results) do
-- PDF/Kopt shows full words when only some part matches; let's do the same with CRE
@ -546,7 +560,6 @@ function ReaderSearch:showFindAllResults(not_cached)
menu = Menu:new{
title = T(_("Search results (%1)"), #self.findall_results),
subtitle = T(_("Query: %1"), self.last_search_text),
item_table = self.findall_results,
items_per_page = self.findall_results_per_page,
covers_fullscreen = true,
is_borderless = true,
@ -568,9 +581,11 @@ function ReaderSearch:showFindAllResults(not_cached)
end
end,
close_callback = function()
self.findall_results_item_index = menu.page * menu.perpage -- save page number to reopen
UIManager:close(menu)
end,
}
menu:switchItemTable(nil, self.findall_results, self.findall_results_item_index)
UIManager:show(menu)
self:showErrorNotification(#self.findall_results)
end

@ -157,6 +157,7 @@ local settingsList = {
clear_location_history = {category="none", event="ClearLocationStack", arg=true, title=_("Clear location history"), reader=true, separator=true},
----
fulltext_search = {category="none", event="ShowFulltextSearchInput", title=_("Fulltext search"), reader=true},
fulltext_search_findall_results = {category="none", event="ShowFindAllResults", title=_("Last fulltext search results"), reader=true},
toc = {category="none", event="ShowToc", title=_("Table of contents"), reader=true},
book_map = {category="none", event="ShowBookMap", title=_("Book map"), reader=true, condition=Device:isTouchDevice()},
book_map_overview = {category="none", event="ShowBookMap", arg=true, title=_("Book map (overview)"), reader=true, condition=Device:isTouchDevice()},
@ -374,6 +375,7 @@ local dispatcher_menu_order = {
"clear_location_history",
----
"fulltext_search",
"fulltext_search_findall_results",
"toc",
"book_map",
"book_map_overview",

@ -211,6 +211,7 @@ local order = {
"----------------------------",
"find_book_in_calibre_catalog",
"fulltext_search",
"fulltext_search_findall_results",
"bookmark_search",
},
search_settings = {

Loading…
Cancel
Save