Repository navigation
feat(editor): formatted paste; drop untyped pending formatting - #30
Merged
Merged
Conversation
- Pasting HTML keeps character formatting, headings, lists, line breaks, tabs and tables (insertFragmentCommand + parseClipboardHtml), from Word, web pages, Google Docs and the editor's own copy. Text drops too. - Formatting set at a caret and left without typing is dropped when the caret moves on (releasePendingFormat), instead of an empty run that swallowed an arrow-key press. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UAiVj14HzKtRDqK12BXTr6
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.
Summary
Pasting in the editor now keeps formatting and structure (bold/italic/underline/strike, super/subscript, color, headings, bullet and numbered lists, line breaks, tabs, tables). Formatting chosen at a caret and abandoned without typing no longer leaves an empty run behind.
Motivation
These were the two issues left open after #29. Until now, pasting from Word, a web page, or the editor itself dropped everything except plain text. Also, after pressing ⌘B at a caret and moving away without typing, an empty bold run stayed in the document. Each arrow key then stopped once on its invisible placeholder. Word handles both cases. There is no linked issue; the maintainer asked for these to be fixed.
Changes
parseClipboardHtml(html)(new, browser-only). Reads clipboard HTML intoPastedBlocks.font-weight:normalwrapper correctly cancels<b>. Black is dropped, so the style's color still applies.h1–h6, and nestedul/ollevels.mso-listparagraphs: the level is read from the style and the kind from the marker. The typed marker itself is dropped. becomes a space.insertFragmentCommand(new). Pastes those blocks as one undo step, the way Word does:releasePendingFormat(model, selection)(new). When the caret leaves the empty run that caret formatting created, without typing, the run is removed and later run indices are shifted. The canvas calls it on selection change and re-renders.applyListCommandand paste (commands/list-util.ts, not exported). The text-split loop is factored out ofinsertTextCommand.Testing
New
clipboard-html.test.ts(happy-dom), 13 tests.validate), table at a paragraph start, table pasted into a cell, list on the first merged paragraph, no leftover empty runs.text-selection.test.ts: pending run dropped when the caret moves, with indices shifted; pending run kept while the caret stays and once text is typed.pnpm test: 1293 passed, 8 skipped.pnpm typecheck,pnpm -r run typecheck,svelte-check,check:api-pageandcheck:tree-shakepass.oxlintreports the 2 known warnings.Chromium,
/editor:Random key fuzzing with pastes and caret formatting mixed in (3 seeds × 200 steps) found no DOM/model mismatch and no invalid package.
Breaking changes
None.
Checklist
🤖 Generated with Claude Code
https://claude.ai/code/session_01UAiVj14HzKtRDqK12BXTr6