Repository navigation
fix(muya): insert ordinary spaces for Tab instead of non-breaking spaces (#3273) - #4634
Merged
Merged
Conversation
…spaces (#3273) `Content.insertTab` and the `ParagraphContent` override wrote `String.fromCharCode(160)` (U+00A0, NBSP) `tabSize` times into the block text. Since the block text is the markdown source, Tab indentation leaked non-breaking spaces into saved files, where many tools do not treat U+00A0 as whitespace. `.mu-content` is `white-space: pre-wrap`, so ordinary spaces are already preserved visually — NBSP was unnecessary. The legacy muyajs engine used charCode 32; this restores that behavior. Updates the characterization spec that previously locked in the NBSP behavior to assert ordinary spaces, and adds a regression test ensuring no U+00A0 reaches the serialized markdown. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
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.
Fixes #3273
Problem
Pressing Tab in the WYSIWYG editor inserted
tabSizenon-breaking spaces (U+00A0, charCode 160) instead of ordinary spaces (U+0020, charCode 32). Because a block's text is its markdown source, this indentation leaked U+00A0 characters into saved.mdfiles — and many tools do not treat U+00A0 as whitespace, so the indentation behaves differently from real spaces (the reporter's "charcode is 160 but charcode of space bar is 32").The legacy muyajs engine already used charCode 32 (
packages/muyajs/lib/contentState/tabCtrl.js); the rewrite re-introduced the NBSP behavior.Root cause
Content.insertTab(packages/muya/src/block/base/content.ts) and theParagraphContent.insertTaboverride (packages/muya/src/block/content/paragraphContent/index.ts) both built the tab string withString.fromCharCode(160).repeat(tabSize).NBSP was unnecessary for display:
.mu-contentiswhite-space: pre-wrap, so runs of ordinary spaces are already preserved visually.Fix
String.fromCharCode(32)(ordinary space) in bothinsertTabsites.Verification
pnpm -C packages/muya exec vitest run src/block/content/paragraphContent/__tests__/insertTabAndIndent.spec.ts— 8/8 pass (RED→GREEN confirmed).lint:typesclean; ESLint clean on changed files (one pre-existing unrelatedarrowHandlercomplexity warning).🤖 Generated with Claude Code