Skip to content

fix(dom): adapt to __reactFiber removal and add cursor/selection change listeners - #252

Merged
takker99 merged 1 commit into
mainfrom
fix/react-fiber-removal
Nov 8, 2026
Merged

takker99 merged 1 commit into
mainfrom
fix/react-fiber-removal

Conversation

@takker99

@takker99 takker99 commented Nov 8, 2026

Copy link
Copy Markdown
Owner

Cosense no longer exposes __reactFiber on 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() and takeInternalLines(), and marking broken internal store accessors as deprecated.

Changes

  • Add addCursorChangeListener and removeCursorChangeListener: Observe style attribute changes on div.cursor with MutationObserver and dispatch standard change events on an internal EventTarget. Automatically re-attach on layout:changed.
  • Add addSelectionChangeListener and removeSelectionChangeListener: Observe addition/removal of div.selections under div#editor and subtree/style mutations inside div.selections. Automatically re-attach on layout:changed.
  • Update caret(): Fall back to { line: 0, char: 0 } when scrapbox.Page.cursor or scrapbox.Page.selection is null, and calculate selectedText dynamically using scrapbox.Page.selection and getCachedLines(). Deprecate caret() and its related types.
  • Update takeInternalLines() and node.ts: Replace takeInternalLines() with getCachedLines() ?? [] and migrate node.ts to getCachedLines(). Deprecate takeInternalLines().
  • Deprecate internal store accessors: Add @deprecated annotations to takeStores(), takeCursor(), and takeSelection().

Test

  • deno task check passes (type-check, tests, formatting check, lint, publish dry-run).

…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.
@takker99
takker99 merged commit d06b6f2 into main Nov 8, 2026
5 checks passed
@takker99
takker99 deleted the fix/react-fiber-removal branch November 8, 2026 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant