feat: output continuous spaces as  #471
Conversation
WalkthroughThis PR introduces whitespace preservation utilities for the editor to maintain consistent spacing in HTML output. Two utility functions are added to handle non-breaking space conversion and decision logic, integrated into keyboard handling via a new space-key binding, and consolidated with existing clipboard processing by removing a duplicate implementation. ChangesWhitespace Preservation Feature
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/fluent-editor/src/config/editor.utils.ts (1)
116-149: ⚡ Quick winAdd focused unit tests for whitespace edge cases.
These rules are easy to regress; please add direct tests for line-start spaces, consecutive in-text spaces, full-width spaces (
\u3000), and prefixes ending with\u00A0.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/fluent-editor/src/config/editor.utils.ts` around lines 116 - 149, Add focused unit tests for replaceStrWhiteSpace and shouldInsertNbspOnSpace covering edge cases: assert replaceStrWhiteSpace turns leading spaces at line-start into '\u00A0', handles consecutive in-text spaces by alternating between normal space and '\u00A0' per the algorithm, correctly processes full-width space '\u3000' as whitespace, and preserves/outputs '\u00A0' where expected; also add tests for shouldInsertNbspOnSpace with empty prefix, prefixes ending in regular space, prefixes ending in '\u00A0', and prefixes ending in '\u3000' to verify true/false returns match the WHITE_SPACE_OR_NBSP_RE logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/fluent-editor/src/config/editor.utils.ts`:
- Around line 116-149: Add focused unit tests for replaceStrWhiteSpace and
shouldInsertNbspOnSpace covering edge cases: assert replaceStrWhiteSpace turns
leading spaces at line-start into '\u00A0', handles consecutive in-text spaces
by alternating between normal space and '\u00A0' per the algorithm, correctly
processes full-width space '\u3000' as whitespace, and preserves/outputs
'\u00A0' where expected; also add tests for shouldInsertNbspOnSpace with empty
prefix, prefixes ending in regular space, prefixes ending in '\u00A0', and
prefixes ending in '\u3000' to verify true/false returns match the
WHITE_SPACE_OR_NBSP_RE logic.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 09a53e87-f240-4058-8f64-547afd7b6531
📒 Files selected for processing (3)
packages/fluent-editor/src/config/editor.utils.tspackages/fluent-editor/src/modules/custom-clipboard.tspackages/fluent-editor/src/themes/snow.ts
将连续空格转为不间断空格,以便 innerHTML 输出 并在预览中保留间距

修改前:
修改后:

PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit