feat(platform): batch annotations without changing undo history - #553
Open
henrique221 wants to merge 2 commits into
Open
henrique221 wants to merge 2 commits into
henrique221 wants to merge 2 commits into
Conversation
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #514.
Adds
setAnnotations(annotations)andremoveAnnotations(refs)to the editor API, with exportedAnnotationandAnnotationReferencetypes. Each batch runs in one editor update. Existing type/id pairs are replaced, unrelated marks stay in place, and the last entry wins when a batch repeats a type/id. Callbacks remain optional. The single-annotation methods use the same path.Annotation updates leave the history entry, undo stack, and redo stack unchanged. Pending user edits are flushed before the annotation update, which commits discretely, so the history exclusion tag cannot discard a real edit from the same tick. The editor's change notifier and Standard view also distinguish these updates from a real undo/redo restore.
Tests cover overlapping ranges, replacement, callbacks, invalid ranges, reserved types, empty batches, 128 diagnostics in one update/commit, undo/redo, and refreshing diagnostics from
onUsjChange. A Standard view regression test checks that annotation updates do not suspend a pending marker edit.Validation:
shared-react: 1,667 passed, one existing skipped test.platform-editor: 1,696 passed.Integration with #531 was verified locally at its head
7a2b8fbf: 36 focused tests and the shared-react/platform typechecks passed. Tests cover both individual and batch annotations at mount, in the same tick assetUsj, and in ordered set/remove pairs. The resolution keepsrunWhenLoadedaround the sharedsetAnnotationsandremoveAnnotationsforwarding inEditor.tsx; the individual methods delegate to them. The set-then-remove assertion in #531 should now expect no remaining mark, because the discrete annotation update commits the index before removal.The load gate remains in #531. Until it lands, the existing requirement to apply annotations after loading still applies. Undo/redo restores document snapshots, so hosts should refresh diagnostics for the restored content.
When combining with #552, preserve the new
AnnotationandAnnotationReferenceexports ineditorial-entry.ts, which that PR introduces and re-exports from the root entry point.This change is
Screenshots
Playwright captures of a local consumer harness loading the real Editor source at
2d91195a. The Genesis USJ fixture is local test data. Counters and result rows come from live editor events,getUsj(), and rendered marks.1. Batch annotations applied in one editor commit
Three diagnostics are applied by one
setAnnotationscall. The real editor reports one annotation commit, zero content changes, and no undo entry.2. Undo and redo after diagnostic refresh
After inserting
!with browser input, the host refreshes diagnostics fromonUsjChange. Undo removes the edit and enables Redo; Redo restores it. The table records the actual text and history state after each action.