Skip to content

fix(muya): insert ordinary spaces for Tab instead of non-breaking spaces (#3273) - #4634

Merged
Jocs merged 1 commit into
developfrom
fix/issue-3273-tab-inserts-nbsp
Jun 22, 2026
Merged

Jocs merged 1 commit into
developfrom
fix/issue-3273-tab-inserts-nbsp

Conversation

@Jocs

@Jocs Jocs commented Jun 22, 2026

Copy link
Copy Markdown
Member

Fixes #3273

Problem

Pressing Tab in the WYSIWYG editor inserted tabSize non-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 .md files — 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 the ParagraphContent.insertTab override (packages/muya/src/block/content/paragraphContent/index.ts) both built the tab string with String.fromCharCode(160).repeat(tabSize).

NBSP was unnecessary for display: .mu-content is white-space: pre-wrap, so runs of ordinary spaces are already preserved visually.

Fix

  • Use String.fromCharCode(32) (ordinary space) in both insertTab sites.
  • Update the characterization spec that previously asserted the NBSP behavior to assert ordinary spaces, and add a regression test verifying no U+00A0 reaches the serialized markdown.

Verification

  • pnpm -C packages/muya exec vitest run src/block/content/paragraphContent/__tests__/insertTabAndIndent.spec.ts — 8/8 pass (RED→GREEN confirmed).
  • Full muya unit suite: 161 files / 1221 tests pass.
  • lint:types clean; ESLint clean on changed files (one pre-existing unrelated arrowHandler complexity warning).

🤖 Generated with Claude Code

…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]>
@Jocs
Jocs merged commit 72886d1 into develop Jun 22, 2026
7 checks passed
@Jocs
Jocs deleted the fix/issue-3273-tab-inserts-nbsp branch October 23, 2026 08:32
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.

Tab is 4 space,charcode is 160,but charcode of space bar is 32

1 participant