Accurate "AnnotationsModified" event handling (#16241)

- Closes #16236
This commit is contained in:
hius07 authored and GitHub committed 2026-10-15 19:35:47 +02:00
1 parent 892034c96e
commit e551601fc4
3 files changed
+16 -8

No files matched your search

@@ -1411,7 +1411,7 @@ function ReaderBookmark:setBookmarkNote(item_or_index, is_new_note, new_note, ca
local value = input_dialog:getInputText()
value = value ~= "" and value or nil -- blank input deletes note
annotation.note = value
local type_after
local type_after, datetime_updated
if type_before ~= "bookmark" then
self.ui.highlight:writePdfAnnotation("content", annotation, value or "")
type_after = self.getBookmarkType(annotation)
@@ -1423,8 +1423,12 @@ function ReaderBookmark:setBookmarkNote(item_or_index, is_new_note, new_note, ca
self.ui:handleEvent(Event:new("AnnotationsModified",
{ annotation, nb_highlights_added = 1, nb_notes_added = -1 }))
end
datetime_updated = true
end
end
if not datetime_updated then
self.ui.annotation:onAnnotationsModified({ annotation })
end
UIManager:close(input_dialog)
if item then
item.note = value
@@ -1503,6 +1507,7 @@ function ReaderBookmark:setHighlightedText(item_or_index, text, caller_callback)
end
annotation.text = text
annotation.text_edited = edited
self.ui.annotation:onAnnotationsModified({ annotation }) -- datetime_updated
if item then
item.text_orig = text
item.text = self:getBookmarkItemText(item)
+4 -2
View File
@@ -985,8 +985,10 @@ function ReaderUI:onOpenLastDoc()
filemanagerutil.openFile(self, self.menu:getPreviousFile())
end
function ReaderUI:onAnnotationsModified()
BookList.setBookInfoCacheProperty(self.document.file, "has_annotations", self.annotation:hasAnnotations())
function ReaderUI:onAnnotationsModified(items)
if items.index_modified then
BookList.setBookInfoCacheProperty(self.document.file, "has_annotations", self.annotation:hasAnnotations())
end
end
function ReaderUI:onDocumentRerendered()
+6 -5
View File
@@ -1,18 +1,17 @@
describe("ReaderAnnotation export and import", function()
local ReaderAnnotation, LuaSettings, Notification, lfs, filepath, original_settings, annotation
local orig_device_id, ReaderAnnotation, Notification, lfs, filepath, annotation
setup(function()
require("commonrequire")
orig_device_id = G_reader_settings:readSetting("device_id", "target")
ReaderAnnotation = require("apps/reader/modules/readerannotation")
LuaSettings = require("luasettings")
Notification = require("ui/widget/notification")
lfs = require("libs/libkoreader-lfs")
filepath = require("datastorage"):getDataDir() .. "/readerannotation.annotations.lua"
end)
before_each(function()
original_settings = G_reader_settings
G_reader_settings = LuaSettings:wrap{ device_id = "source" }
G_reader_settings:saveSetting("device_id", "source")
stub(Notification, "notify")
os.remove(filepath)
os.remove(filepath .. ".old")
@@ -24,7 +23,7 @@ describe("ReaderAnnotation export and import", function()
end)
after_each(function()
G_reader_settings = original_settings
G_reader_settings:saveSetting("device_id", orig_device_id)
Notification.notify:revert()
os.remove(filepath)
os.remove(filepath .. ".old")
@@ -56,6 +55,7 @@ describe("ReaderAnnotation export and import", function()
end)
it("should not export on closing when disabled", function()
G_reader_settings:saveSetting("annotations_export_on_closing", false)
annotation.annotations = {{ page = 1, datetime = "2020-01-01 00:00:00" }}
annotation:onExportAnnotations(true)
assert.is_nil(lfs.attributes(filepath, "mode"))
@@ -109,6 +109,7 @@ describe("ReaderAnnotation export and import", function()
it("should import an empty rolling snapshot", function()
G_reader_settings:saveSetting("annotations_export_on_closing", true)
G_reader_settings:saveSetting("annotations_export_keep_all_on_import", false)
annotation.ui = { rolling = true }
export_empty()
annotation.annotations = {{ page = "/body/p[1]", datetime = "2020-01-01 00:00:00" }}