Repository navigation
fix(dom): adapt to __reactFiber removal and add cursor/selection change listeners - #252
Merged
Merged
Conversation
…ge listeners Cosense no longer exposes __reactFiber on DOM elements, breaking internal store accessors. This change introduces MutationObserver-based listeners for cursor and selection changes, re-implements caret() and takeInternalLines() using public Cosense APIs, and deprecates functions relying on __reactFiber.
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.
Cosense no longer exposes
__reactFiberon DOM elements, which broke internal cursor/selection store access and internal lines extraction.This PR adapts to the specification change by introducing standard MutationObserver-based listeners, re-implementing
caret()andtakeInternalLines(), and marking broken internal store accessors as deprecated.Changes
addCursorChangeListenerandremoveCursorChangeListener: Observestyleattribute changes ondiv.cursorwithMutationObserverand dispatch standardchangeevents on an internalEventTarget. Automatically re-attach onlayout:changed.addSelectionChangeListenerandremoveSelectionChangeListener: Observe addition/removal ofdiv.selectionsunderdiv#editorand subtree/style mutations insidediv.selections. Automatically re-attach onlayout:changed.caret(): Fall back to{ line: 0, char: 0 }whenscrapbox.Page.cursororscrapbox.Page.selectionisnull, and calculateselectedTextdynamically usingscrapbox.Page.selectionandgetCachedLines(). Deprecatecaret()and its related types.takeInternalLines()andnode.ts: ReplacetakeInternalLines()withgetCachedLines() ?? []and migratenode.tstogetCachedLines(). DeprecatetakeInternalLines().@deprecatedannotations totakeStores(),takeCursor(), andtakeSelection().Test
deno task checkpasses (type-check, tests, formatting check, lint, publish dry-run).