Skip to content

Add undo/redo and history-aware annotation editing to index.android.js - #271

Merged
mrtcode merged 2 commits into
zotero:masterfrom
Dima-Android:master
Nov 9, 2026
Merged

mrtcode merged 2 commits into
zotero:masterfrom
Dima-Android:master

Conversation

@Dima-Android

@Dima-Android Dima-Android commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Lets the Android embedder use the reader's existing undo/redo history, and makes the annotation changes the client makes itself (highlight from a text selection, color/size/width/comment edits, deletes) land in that history.

Relevant changes on Android zotero/zotero-android@4d26ed043c8a

Dima-Android and others added 2 commits November 3, 2026 07:20
Route ink erasure through history and retain immediate-save requests.
Preserve queued deletions across Undo/Redo ID changes and ignore stale IDs.
@mrtcode

mrtcode commented Nov 5, 2026

Copy link
Copy Markdown
Member

This PR should be good now, though AI agent noticed some issues on the Android side that might need investigation:


File: app/src/main/java/org/zotero/android/screens/reader/ReaderViewModel.kt
Companion commit: https://github.com/zotero/zotero-android/commit/4d26ed043c8ad4cd2583fde6eaabb8e61a8a031a

onCommentTextChange() queues edits through a 500 ms debounce, but onUndoClick()
and onRedoClick() call Reader immediately. A delayed comment can therefore
arrive after Undo as a new edit, reapplying the text and clearing Redo.

Before invoking Reader's Undo/Redo:
1. Consume any pending comment and prevent its delayed emission.
2. Send the comment edit to Reader and await its JavaScript evaluation,
   including any comment dispatch already in flight.
3. Then invoke Undo/Redo.

Keep normal typing debounced. Do not resend an already-delivered comment:
MutableStateFlow retains its last value even after that value was processed.
This ordering belongs in the app; Reader cannot flush text it hasn't received.

Verify: with an existing undoable action, type a comment and press Undo within
500 ms. Wait longer than 500 ms: the comment must stay undone, and Redo must
restore it. Also verify that Undo/Redo after an already-delivered edit does not
resend stale text. Cover PDF, EPUB, and snapshot.

Validation: reproduced by simulating the app's delay against the real built
Reader in all three views. The packaged Android app has not been tested.

@Dima-Android

Copy link
Copy Markdown
Contributor Author

Thanks for the heads up, indeed there was a bug. I've also fixed some other relates issues. Now it works better and I think it's ok for you to merge, if anything else comes up we can address it later.

@mrtcode
mrtcode merged commit 7276c54 into zotero:master Nov 9, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants