Skip to content

Resolve Blocks by holder identity instead of working-area child index#3009

Open
joecrop wants to merge 1 commit into
codex-team:nextfrom
joecrop:fix/block-index-skew-from-non-block-children
Open

Resolve Blocks by holder identity instead of working-area child index#3009
joecrop wants to merge 1 commit into
codex-team:nextfrom
joecrop:fix/block-index-skew-from-non-block-children

Conversation

@joecrop

@joecrop joecrop commented Jun 11, 2026

Copy link
Copy Markdown

BlockManager.getBlock() and setCurrentBlockByChildNode() resolved a Block by taking indexOf(wrapper) over Blocks.nodes — which is Array.from(workingArea.children) — and using that position to index the blocks array. The two lists are only aligned when the working area contains nothing but Block holders. When a host application adds non-block elements between blocks (visual decorations such as page-break spacers in a paginated view), every Block below such an element resolves to the wrong index: the editor marks the wrong Block as current, and for the last Block the index lands past the end of the blocks array, throwing

TypeError: Cannot read properties of undefined (reading 'updateCurrentInput')

on any click into the block or below it (Ui.processBottomZoneClick → Caret.setToTheLastBlock, and Ui.selectionChanged).

Both methods now find the Block by holder identity, the same idiom already used by getBlockByChildNode() and RectangleSelection. setCurrentBlockByChildNode() also returns undefined for a wrapper element that matches no managed Block instead of corrupting currentBlockIndex, matching its documented return type.

Adds a mousedown regression test that inserts a non-block element into the redactor and clicks the block below it — it fails with the updateCurrentInput TypeError before this change.

BlockManager.getBlock() and setCurrentBlockByChildNode() resolved a
Block by taking indexOf(wrapper) over Blocks.nodes — which is
Array.from(workingArea.children) — and using that position to index the
blocks array. The two lists are only aligned when the working area
contains nothing but Block holders. When a host application adds
non-block elements between blocks (visual decorations such as
page-break spacers in a paginated view), every Block below such an
element resolves to the wrong index: the editor marks the wrong Block
as current, and for the last Block the index lands past the end of the
blocks array, throwing

  TypeError: Cannot read properties of undefined (reading 'updateCurrentInput')

on any click into the block or below it (Ui.processBottomZoneClick →
Caret.setToTheLastBlock, and Ui.selectionChanged).

Both methods now find the Block by holder identity, the same idiom
already used by getBlockByChildNode() and RectangleSelection.
setCurrentBlockByChildNode() also returns undefined for a wrapper
element that matches no managed Block instead of corrupting
currentBlockIndex, matching its documented return type.

Adds a mousedown regression test that inserts a non-block element into
the redactor and clicks the block below it — it fails with the
updateCurrentInput TypeError before this change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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