Repository navigation
fix(muya): run paragraph commands on the whole table or code block (#4944) - #5358
Merged
Merged
Conversation
…4944) The paragraph commands took "the block at the caret" to be the caret leaf's parent. In a table cell that is the cell, and in a code, math, html, diagram or front matter block it is the inner code node; neither is a block in the json state. So with the caret there: - Paragraph > Heading 1 (or another type the block cannot turn into) inserted the heading into the table row or into the code block, - Insert Paragraph Before/After inserted the paragraph there, - Insert Table inserted or replaced the table there, and the json flush threw "Cannot use numerical key for object container", then kept throwing on every later edit, so nothing else reached the saved markdown. The desktop disables the Paragraph menu in tables and code blocks, but the command palette runs these commands directly. Resolve the block from the leaf's anchor (the whole table or code-like block), as muyajs `getAnchor` did, and keep muyajs's rules for it: such a block is never converted into another type, Insert Table never replaces it because its first leaf is empty, and no paragraph is inserted before front matter. Toggling a code block off still works. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01WEPLCvFTgbYf35z85XUJop
7 of 10 tasks
1 task done
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.
Closes #4944
Summary
#4944 is a crash report without steps:
Cannot use numerical key for object container, thrown by ot-json1 insideJSONState._flushOperationCache. Earlier fixes covered two actions that throw it (#4913, #5347). Fuzzing currentdevelopfound another one, fixed here.The paragraph commands took "the block at the caret" to be the caret leaf's parent (
_immediateBlockAtCursor()→content.parent). In a table cell that is thetable.cell; in a code, math, html, diagram or front matter block it is the innercodenode. Neither is a block in the json state. With the caret there:and the json flush threw
Cannot use numerical key for object container. After that it threw on every later edit, so nothing else reached the saved markdown. The desktop disables the Paragraph menu inside tables and code blocks, but the editor context menu's Insert Paragraph items and the command palette run the same commands there.Resolve the block from the leaf's anchor (
getAnchor(), the whole table or code-like block), as muyajsgetAnchordid, and keep the muyajs rules for such a block (isAllowedTransformation,insertParagraph,createFigure):Toggling a code block off (Code Fences with the caret in code) still works:
_toggleIfActiveruns first.Steps to reproduce
Checked on the released MarkText 0.20.0-rc.2 (macOS) and on a desktop build of this PR (with #5357), with real mouse and keyboard input. To set up a document, open a new tab, switch to source code mode (⌘⌥S / Ctrl+Alt+S), paste the markdown, and switch back. After the first error every later edit throws again until the file is reopened, so use a new tab for each step.
1. Insert Paragraph from the context menu
2, right-click, choose Insert Paragraph After, then typebelow.Cannot use numerical key for object container;belowis never saved.belowafter the table.code, right-click, choose Insert Paragraph Before, then typeabove.abovebefore the code block.2. Paragraph commands from the command palette
The Paragraph menu (and its shortcuts) is disabled in tables and code blocks, but the command palette (⌘⇧P / Ctrl+Shift+P) runs the same commands.
2(or incode), open the command palette and run Heading 1.code, run Table, and click OK in the dialog.code, run Paragraph (the command named just "Paragraph", not Create / Delete / Reset Paragraph).3. Front matter
Click in
title: x, right-click, choose Insert Paragraph Before.Also covered by the unit tests: Bullet List / Horizontal Line with the caret in a math or html block (the same error), and Heading 1 in the empty language input of a code block without a language (on
developthe code block is replaced by an empty heading).Type of change
Test plan
src/__tests__/paragraphMenuInTableOrCode4944.spec.ts(13 cases). Each flushes the json state and compares it with the block tree. All 13 fail ondevelop.editing/paragraph-menu-in-table-or-code-4944.spec.ts(table cell, code block; checks the saved markdown and page errors). Both fail ondevelop; Chromium repeated 6/6 with the fix._electron, real mouse clicks and keyboard; the context-menu items were driven through themt::cm-insert-paragraphmessage they send): every step above on the packaged 0.20.0-rc.2 gives the listed result, and on abuild:unpackof this branch (with fix(muya): don't drop blocks when a cut ends inside a code block (#4903, #5148) #5357) gives no error and the listed document.vitest run230 files / 1642 tests (existingupdateParagraph,insertParagraph,createTableand front matter specs included);lint:types, eslint on the changed files andcheck-circularpass.Notes for reviewers
The fuzzing run also hit errors outside #4944, not changed here: a table's
get pathon a detached row (7 of 90 seeds),Cannot read properties of undefined (reading 'trim')in the table serializer,Invalid offset - splits unicode bytes, and aMaximum call stack size exceededin fast-diff.By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.
🤖 Generated with Claude Code
https://claude.ai/code/session_01WEPLCvFTgbYf35z85XUJop