Skip to content

[pull] develop from marktext:develop#95

Merged
pull[bot] merged 1 commit into
code:developfrom
marktext:develop
Jun 24, 2026
Merged

[pull] develop from marktext:develop#95
pull[bot] merged 1 commit into
code:developfrom
marktext:develop

Conversation

@pull

@pull pull Bot commented Jun 24, 2026

Copy link
Copy Markdown

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.4)

Can you help keep this open source service alive? 💖 Please sponsor : )

…its (#4669)

* fix(muya): invert undo/redo ops against the live document

History._change rebuilt the reverse op with the bare `json1.type.invert`,
which trusts the removed values carried in the op. A coalesced entry that
removes a subtree containing a text edit records the POST-edit removed
value (e.g. an empty list item after the typed characters were composed
away), so redo re-inserted a node missing the typed text and a follow-up
edit threw "The op is too long for this document".

Invert against the current json state with `invertWithDoc` so the true
removed value is reread, keeping undo/redo lossless.

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

* fix(muya): append at end when undo/redo replaces the last block

The incremental updateContents walker mishandled a block replace at the
last child index: the pick phase removes the old block, then drop calls
`insertBefore(newBlock, ref)` where `ref` is now undefined — a no-op, so
the new block was silently dropped and the live DOM desynced from the
json state. A later op then walked a missing path and crashed with
"Cannot read properties of undefined (reading 'blockName')".

Append the block when there is no insert reference (end of the list).

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

* fix(muya): restore selection by path after a structural undo/redo

Restoring an undo/redo selection trusted the cached `anchor.block` /
`focus.block` references, but a structural op (e.g. a paragraph→list
replace) detaches those blocks. Setting a DOM range on a detached node
logged "addRange(): The given range isn't in document", and reading the
detached block's path/blockName in a later getSelection() threw.

Re-resolve both endpoints from their path against the fresh tree and
focus a valid block when the path no longer points at content; bail out
of getSelection() when an endpoint is detached.

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

* test(muya): cover undo/redo of a coalesced paragraph→list + text edit

Reproduces the reported corruption (type "- " to make a list, type text,
undo twice, redo): redo must restore the typed text losslessly and the
caret-inside-converted-block path must not crash. Asserts the live block
tree (not just getMarkdown, which reads the json state) so a DOM/state
desync can't pass silently.

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

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@pull pull Bot locked and limited conversation to collaborators Jun 24, 2026
@pull pull Bot added the ⤵️ pull label Jun 24, 2026
@pull pull Bot merged commit d37bc01 into code:develop Jun 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant