Skip to content

Build your personal knowledge base with Trilium Notes

fix(client/pdfjs): not reacting to all changes

Elian Doran08f6a32c34e1
diff --git a/packages/pdfjs-viewer/src/custom.mjs b/packages/pdfjs-viewer/src/custom.mjs
index 1f75add446..a09e6c9f99 100644
--- a/packages/pdfjs-viewer/src/custom.mjs
+++ b/packages/pdfjs-viewer/src/custom.mjs
@@ -16,8 +16,8 @@ async function main() {
clearTimeout(timeout);
}
timeout = setTimeout(async () => {
- console.log("Triggered debounce save");
- const data = await app.pdfDocument.saveDocument();
+ if (!storage) return;
+ const data = await app.pdfDocument.saveDocument(storage);
window.parent.postMessage({
type: "pdfjs-viewer-document-modified",
data: data
@@ -27,9 +27,16 @@ async function main() {
}, 2_000);
}
- storage.onSetModified = async () => {
- debouncedSave();
- };
+ app.eventBus.on("annotationeditorcommit", debouncedSave);
+ app.eventBus.on("annotationeditorparamschanged", debouncedSave);
+ app.eventBus.on("annotationeditorstateschanged", evt => {
+ const { activeEditorId } = evt;
+
+ // When activeEditorId becomes null, an editor was just committed
+ if (activeEditorId === null) {
+ debouncedSave();
+ }
+ });
});
};