Skip to content

markdown: Fix markdown copy range resolution#50411

Open
pkondzior wants to merge 1 commit intozed-industries:mainfrom
pkondzior:fix-markdown-select-text-copy
Open

markdown: Fix markdown copy range resolution#50411
pkondzior wants to merge 1 commit intozed-industries:mainfrom
pkondzior:fix-markdown-select-text-copy

Conversation

@pkondzior
Copy link
Contributor

Summary

Markdown copy could break formatting when selection edges landed inside wrapper syntax, producing output like bold** instead of **bold**. This PR makes copy range resolution span-aware, so copied markdown keeps valid boundaries.

Why

The old flow used raw source slicing. That works for plain text but is fragile for formatted markdown. Using parse-time span metadata makes selection-to-source mapping consistent for wrappers like bold, links, and inline code.

What changed

The markdown parser now keeps wrapper bounds for inline code, and markdown copy resolution now runs through source-span normalization and wrapper expansion logic. Copy still falls back to clamped raw selection when parsed source is stale. Tests were expanded across parser, resolver, and markdown integration paths.

Cases covered

Case Description Before After
1. Full formatted token selection Selecting visible text inside a full formatted token now copies the full markdown wrapper. Case 1 before Case 1 after
2. Partial formatted token selection Selecting only part of formatted content now copies only that part, without leaking wrapper syntax. Case 2 before Case 2 after
3a. Link boundary handling Selections near link edges no longer leak broken suffixes like ](...). Case 3a before Case 3a after
3b. Link boundary handling (additional) Additional boundary scenario for links now resolves cleanly. Case 3b before Case 3b after
4. Multiline list boundary handling Selections spanning list items now start cleanly and do not inherit suffix fragments from prior items. Case 4 before Case 4 after
5. List boundary with inline style wrapper If a selection begins at a list-item boundary inside visible styled text, copy now preserves complete inline style wrappers. Case 5 before Case 5 after

Closes #42958

  • Added solid test coverage and/or manual testing screenshots
  • Completed self-review, including security and performance considerations
  • Aligned UI changes with the UI/UX checklist

Release Notes:

  • Fixed markdown copy behavior for formatted selections.

Markdown copy still used raw selection slicing, which could split
wrapper syntax and produce malformed output like `bold**`. This change
resolves copy ranges from parse-time source spans so selection
boundaries stay valid for formatted markdown. Inline code events now
retain wrapper ranges, stale-parse fallback is preserved, and regression
coverage was added for links, inline code, nested wrappers, and
multiline selections.

Release Notes:

- Fixed markdown copy behavior for formatted selections.
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Feb 28, 2026
@pkondzior pkondzior marked this pull request as ready for review February 28, 2026 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AI: copying and pasting from AI window sometimes gives incomplete markdown

1 participant