diff --git a/frontend/apps/filemanager/filemanager.lua b/frontend/apps/filemanager/filemanager.lua index e2c0767fd..f9c8e75a1 100644 --- a/frontend/apps/filemanager/filemanager.lua +++ b/frontend/apps/filemanager/filemanager.lua @@ -28,6 +28,7 @@ local ReadCollection = require("readcollection") local ReaderDeviceStatus = require("apps/reader/modules/readerdevicestatus") local ReaderDictionary = require("apps/reader/modules/readerdictionary") local ReaderWikipedia = require("apps/reader/modules/readerwikipedia") +local ReadHistory = require("readhistory") local Screenshoter = require("ui/widget/screenshoter") local TitleBar = require("ui/widget/titlebar") local VerticalGroup = require("ui/widget/verticalgroup") @@ -893,7 +894,9 @@ function FileManager:pasteHere(file) if self:moveFile(orig_file, dest_path) then if is_file then DocSettings:updateLocation(orig_file, dest_file) - require("readhistory"):updateItemByPath(orig_file, dest_file) -- (will update "lastfile" if needed) + ReadHistory:updateItemByPath(orig_file, dest_file) -- (will update "lastfile" if needed) + else + ReadHistory:updateItemsByPath(orig_file, dest_file) end ReadCollection:updateItemByPath(orig_file, dest_file) return true @@ -1016,7 +1019,7 @@ function FileManager:deleteFile(file, is_file) if ok and not err then if is_file then DocSettings:updateLocation(file) - require("readhistory"):fileDeleted(file) + ReadHistory:fileDeleted(file) end ReadCollection:removeItemByPath(file, not is_file) return true @@ -1065,7 +1068,9 @@ function FileManager:renameFile(file, basename, is_file) if self:moveFile(file, dest) then if is_file then DocSettings:updateLocation(file, dest) - require("readhistory"):updateItemByPath(file, dest) -- (will update "lastfile" if needed) + ReadHistory:updateItemByPath(file, dest) -- (will update "lastfile" if needed) + else + ReadHistory:updateItemsByPath(file, dest) end ReadCollection:updateItemByPath(file, dest) self:onRefresh() diff --git a/frontend/readhistory.lua b/frontend/readhistory.lua index 1e634e881..3a6dec044 100644 --- a/frontend/readhistory.lua +++ b/frontend/readhistory.lua @@ -189,6 +189,7 @@ function ReadHistory:getFileByDirectory(directory, recursive) end end +--- Updates the history list after renaming/moving a file. function ReadHistory:updateItemByPath(old_path, new_path) local index = self:getIndexByFile(old_path) if index then @@ -199,6 +200,22 @@ function ReadHistory:updateItemByPath(old_path, new_path) end end +--- Updates the history list after renaming/moving a folder. +function ReadHistory:updateItemsByPath(old_path, new_path) + old_path = "^"..old_path + local history_updated + for i, v in ipairs(self.hist) do + local file, count = v.file:gsub(old_path, new_path) + if count == 1 then + self.hist[i].file = file + history_updated = true + end + end + if history_updated then + self:_flush() + end +end + --- Updates the history list after deleting a file. function ReadHistory:fileDeleted(path) local index = self:getIndexByFile(path)