Skip to content

Preserve list formatting when copy/pasting list items (#19)#24

Merged
Wavesonics merged 2 commits into
mainfrom
fix/issue-19-list-copy-paste
Jun 12, 2026
Merged

Preserve list formatting when copy/pasting list items (#19)#24
Wavesonics merged 2 commits into
mainfrom
fix/issue-19-list-copy-paste

Conversation

@Wavesonics

Copy link
Copy Markdown
Owner

Problem

Copy/pasting one or more numbered- (or bulleted-) list items dropped the list formatting: the pasted lines were oddly indented but no longer rendered as numbered/bulleted items.

Root cause

Line-anchored rich spans (OrderedListSpanStyle, BulletListSpanStyle, blockquote, code fence) are stored in RichSpanManager, separate from the AnnotatedString the clipboard carries. The list's paragraph indent is baked into the AnnotatedString (via applyLineBlock's withStyle(paragraphStyle)), so it survived copy→paste — but the rich span that draws the numeral/bullet did not. Result: pasted lines kept the indent yet lost the marker.

Fix

Remember the rich spans within the copied range in a small in-editor buffer (copyRichSpans) and re-apply them on paste (pasteRichSpans), mirroring the existing undo/redo PreservedRichSpan machinery. A text-match guard ensures the remembered spans are only restored when the pasted text matches what was copied, so content pasted from another source doesn't pick up stale spans.

This is a common-code solution; no platform clipboard files were touched. External (cross-app) copy/paste behavior is unchanged.

Tests

Added RichSpanClipboardTest:

  • copy/paste of ordered-list lines preserves the ordered-list spans
  • paste does not apply stale spans when the pasted text differs from what was copied

Full module suite: :ComposeTextEditor:desktopTest — 431 tests, 0 failures.

Fixes #19

Wavesonics and others added 2 commits June 11, 2026 22:45
Line-anchored rich spans (ordered/bullet lists, blockquote, code fence)
live in RichSpanManager, not in the AnnotatedString the clipboard carries.
A copy/paste round-trip therefore kept the paragraph indent (which is part
of the AnnotatedString) but dropped the rich span, so pasted list lines
were indented yet no longer rendered as numbered/bulleted items.

Remember the rich spans within the copied range in an in-editor buffer and
re-apply them on paste of the same text, mirroring the existing undo/redo
PreservedRichSpan machinery. The text-match guard keeps stale spans off
content pasted from another source.

Fixes #19

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Clamp copied rich spans to the copy range so a span partially overlapping
the selection no longer yields negative relative offsets and a corrupt
span on paste; skip spans that collapse to empty after clamping.

Invalidate the in-editor rich-span buffer on any document edit that is not
the cut/paste's own edit, so a buffer captured before an intervening edit
(or identical text copied from another source after the document changed)
cannot apply stale spans. The text-equality match remains a secondary
guard. Cut and paste arm a one-edit exemption so they keep the buffer they
depend on.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@Wavesonics Wavesonics marked this pull request as ready for review June 12, 2026 06:13
@Wavesonics Wavesonics merged commit a8a9b7c into main Jun 12, 2026
1 check passed
@Wavesonics Wavesonics deleted the fix/issue-19-list-copy-paste branch June 12, 2026 06:47
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.

Copy/pasting list items loses numbering and indents incorrectly

1 participant