Skip to content

List: Keep nested lists when pasting a copied list item into a list - #84115

Open
im3dabasia wants to merge 10 commits into
trunkfrom
fix/list-copy-nested-71317
Open

im3dabasia wants to merge 10 commits into
trunkfrom
fix/list-copy-nested-71317

Conversation

@im3dabasia

@im3dabasia im3dabasia commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

What?

Closes #71317

Pasting a copied list item into another list item now keeps its nested list.

Why?

Copying an item with sub-items works since #80462. Pasting it into a list still fails in two ways.

1. The nested list is dropped when pasting into an item with text

  • Pasting at the end of "item 1.1" gives "item 1.1item 3" without 3.1–3.3.
  • This is what the issue describes.

2. Nothing is pasted into an empty list item

How?

  • Fixes 1: the paste merge now keeps the merged item's inner blocks, not just its text.
  • Fixes 2: an empty or fully selected block is now replaced only after the pasted blocks are converted to fit, as @Mamaduka suggested.

Pasting into the middle of an item's text still joins the text, e.g. "item 1.1item 3". This is the existing behaviour for every block type that can merge, like paragraphs, and is unchanged here. This PR only stops the nested list from being lost.

Testing Instructions

  1. Create a post with the list from List block: unable to cut or copy main item if sub-items exist #71317.
  2. Drag from "item 3" down to "item 3.3", then copy.
  3. Paste into an empty list item: "item 3" arrives with its sub-items.
  4. Paste at the end of "item 1.1": its sub-items come along too.
  5. Paste into a new paragraph below the list: still works as before.

Testing Instructions for Keyboard

  1. Place the caret at the end of "item 3".
  2. Press Shift+Right twice to extend into "item 3.1", then Cmd+C.
  3. Move to an empty list item and press Cmd+V.

Screenshots or screencast

Before After
Screen.Recording.2026-10-06.at.5.51.19.PM.mov
temp-bug-1.mov
Screen.Recording.2026-10-06.at.5.51.50.PM.mov
temp-bug-2.mov

Use of AI Tools

Authored with Claude Code under my direction; I reviewed the changes and tested them manually.

@im3dabasia im3dabasia self-assigned this Oct 6, 2026
@im3dabasia
im3dabasia requested a review from ellatrix as a code owner October 6, 2026 12:24
@im3dabasia im3dabasia added [Type] Bug An existing feature does not function as intended [Feature] Paste [Block] List Affects the List Block labels Oct 6, 2026
@github-actions github-actions Bot added the [Package] Block editor /packages/block-editor label Oct 6, 2026
@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: im3dabasia <im3dabasia1@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: Rishit30G <rishit30g@git.wordpress.org>
Co-authored-by: sanketio <sanketparmar@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
Co-authored-by: annezazu <annezazu@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

📦 Bundle size

Size Change: +27 B (0%)

Total Size: 8.66 MB

📦 View Changed
Filename Size Change
build/scripts/block-editor/index.min.js 555 kB +27 B (0%)

590728f Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric d4b163a trunk % Change
timeToFirstByte 34.7 ms +16.43% -2.59% 38.1 ms +5.25% -5.38% -8.92%
largestContentfulPaint 60 ms +6.67% -6.67% 62 ms +6.45% -3.23% -3.23%
lcpMinusTtfb 22.6 ms +17.04% -4.42% 23.55 ms +17.83% -9.55% -4.03%
wpBeforeTemplate 18.27 ms +15.05% -1.48% 19.44 ms +13.12% -5.2% -6.02%
wpTemplate 13.42 ms +7.97% -3.8% 14.63 ms +5.74% -6.63% -8.27%
wpTotal 31.61 ms +16.48% -2.34% 34.55 ms +5.93% -4.75% -8.51%
wpMemoryUsage 7.75 MB +0% -0% 7.71 MB +0% -0% 0.45%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric d4b163a trunk % Change
timeToFirstByte 29.5 ms +11.53% -2.54% 30.95 ms +9.37% -1.29% -4.68%
largestContentfulPaint 56 ms +10.71% -7.14% 56 ms +7.14% -0% 0%
lcpMinusTtfb 26.35 ms +3.8% -9.49% 26 ms +9.42% -2.69% 1.35%
wpBeforeTemplate 16.37 ms +13.19% -1.89% 16.95 ms +8.67% -2.48% -3.42%
wpTemplate 10.52 ms +1.9% -2.57% 11.37 ms +9.59% -5.98% -7.48%
wpTotal 26.87 ms +11.98% -2.08% 28.11 ms +9.89% -1.57% -4.41%
wpMemoryUsage 6.44 MB +0% -0% 6.40 MB +0% -0% 0.56%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric d4b163a trunk % Change
mediaProcessingJpeg 227.67 ms +2.8% -0.56% 224.78 ms +2.5% -1.2% 1.29%
mediaProcessingAvif 3767.48 ms +0.54% -0.13% 3635.35 ms +1.11% -0.86% 3.63%
mediaProcessingJpegToAvif 2641.34 ms +0.89% -0.61% 2558.81 ms +1.02% -0.68% 3.23%

media-upload

Metric d4b163a trunk % Change
jpegUploadProcessing 1444.16 ms +1.47% -1.19% 1423.14 ms +1.49% -0.83% 1.48%
pngUploadProcessing 204.49 ms +17.58% -4.86% 190.48 ms +2.05% -6.32% 7.36%
largeJpegUploadProcessing 1442.35 ms +0.92% -0.63% 1427.11 ms +0.5% -0.75% 1.07%
multipleImageUploadProcessing 1491.24 ms +1.18% -0.24% 1462.23 ms +2.26% -0.75% 1.98%

post-editor

Metric d4b163a trunk % Change
serverResponse 241.56 ms +2.61% -7.03% 235 ms +5.35% -6.21% 2.79%
firstPaint 265.07 ms +8.57% -10.06% 240.92 ms +6.61% -2.49% 10.02%
domContentLoaded 489.07 ms +2.64% -1.47% 484.29 ms +0.58% -0.88% 0.99%
loaded 489.8 ms +2.67% -1.49% 485.07 ms +0.6% -0.92% 0.98%
firstContentfulPaint 286.84 ms +11.01% -2.82% 281.99 ms +1.51% -0.75% 1.72%
firstBlock 1266.64 ms +6.85% -1.23% 1269.21 ms +1.34% -1.97% -0.2%
type 11.18 ms +2.86% -11.72% 11.22 ms +3.48% -6.33% -0.36%
typeWithoutInspector 11.57 ms +2.77% -12.71% 11.07 ms +2.89% -7.32% 4.52%
typeWithTopToolbar 13.89 ms +2.74% -3.96% 13.99 ms +2.36% -7.43% -0.71%
typeContainer 5.04 ms +10.71% -8.73% 5.46 ms +5.49% -14.1% -7.69%
focus 67.78 ms +8.91% -4.29% 63.86 ms +4.87% -3.13% 6.14%
firstFocus 147.29 ms +0% -0% 147.54 ms +0% -0% -0.17%
selectAll 216.7 ms +2.21% -1.66% 214.32 ms +2.93% -2.15% 1.11%
undo 16.64 ms +13.4% -3.73% 17.12 ms +9.23% -8.24% -2.8%
listViewOpen 42.6 ms +6.57% -11.34% 40.43 ms +7.59% -5.14% 5.37%
inserterOpen 24.8 ms +12.34% -3.59% 23.88 ms +14.57% -5.65% 3.85%
inserterHover 7.34 ms +6.4% -5.86% 7.24 ms +9.25% -5.39% 1.38%
inserterSearch 5.66 ms +5.3% -4.24% 5.51 ms +5.99% -4.9% 2.72%
loadPatterns 387.42 ms +2.21% -2% 384.36 ms +5.33% -2.7% 0.8%
wpTotal 235.14 ms +2.62% -7.27% 228.07 ms +5.77% -6.16% 3.1%
wpMemoryUsage 14.81 MB +0% -0% 14.77 MB +0% -0% 0.25%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric d4b163a trunk % Change
serverResponse 388.95 ms +4.01% -6.69% 407.95 ms +0.68% -1.65% -4.66%
firstPaint 395.86 ms +13.44% -6.57% 402.11 ms +4.37% -5.15% -1.55%
domContentLoaded 843.94 ms +0.47% -2.86% 832.67 ms +0.75% -0.99% 1.35%
loaded 845 ms +0.48% -2.88% 833.88 ms +0.72% -1.01% 1.33%
firstContentfulPaint 468.44 ms +4.37% -3.32% 463.41 ms +1.67% -1.08% 1.09%
firstBlock 2497.21 ms +5.22% -1.57% 2493.77 ms +0.67% -0.9% 0.14%
type 17.81 ms +10.95% -6.79% 18.02 ms +4% -8.55% -1.17%
navigate 122.26 ms +2.37% -3.79% 109.31 ms +7.77% -5.74% 11.85%
loadPatterns 1472.87 ms +2.53% -17.23% 1361.03 ms +9.62% -2.83% 8.22%
loadPages 906.83 ms +1.05% -1.07% 913.29 ms +5.13% -0.23% -0.71%
wpTotal 378.28 ms +4.07% -6.86% 397.1 ms +0.75% -1.67% -4.74%
wpMemoryUsage 12.82 MB +0% -0% 12.79 MB +0% -0% 0.25%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

590728f Run

🏁 Flaky tests

Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

Regression: updating a specific option will only change its value and will not corrupt others in /test/e2e/specs/editor/various/core-settings.spec.js, passed after 1 failed attempt.
Error: expect(received).toStrictEqual(expected) // deep equality

- Expected  - 1
+ Received  + 1

  Array [
    "rewrite_rules",
-   "SERIALIZED DATA",
+   "",
  ]
    at forEach (/home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/core-settings.spec.js:46:26)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/core-settings.spec.js:43:35
should cut and paste individual blocks with collapsed selection in /test/e2e/specs/editor/various/copy-cut-paste.spec.js, passed after 1 failed attempt.
Error: expect(string).toMatchSnapshot(expected) failed

  @@ -1,3 +1,3 @@
   <!-- wp:paragraph -->
  -<p>2Cut - collapsed selection</p>
  +<p>2</p>
   <!-- /wp:paragraph -->


    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/copy-cut-paste.spec.js:45:49

From 576de08, not the current head. Run

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Pasting into an item that already has children can silently delete its existing nested list.

1 open finding
What changed in this PR

Preserves nested list items during copy/paste operations.

Changes:

  • Retains inner blocks when merging pasted list items.
  • Handles pasting into empty list items.
  • Adds end-to-end coverage and a changelog entry.
File Description
packages/​block-editor/​src/​store/​actions.js Preserves inner blocks during merges.
packages/​block-editor/​src/​components/​writing-flow/​use-clipboard-handler.js Converts invalid replacement blocks before pasting.
test/​e2e/​specs/​editor/​blocks/​list.spec.js Tests nested-list copy, cut, and paste.
packages/​block-editor/​CHANGELOG.md Documents the fix.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

@@ -1228,6 +1228,9 @@ export const __unstableSplitSelection =
...head.attributes,
...headType.merge( head.attributes, first.attributes ),
},
// Keep the merged block's inner blocks, like the nested list
// of a pasted list item.
innerBlocks: [ ...head.innerBlocks, ...first.innerBlocks ],
@youknowriad

Copy link
Copy Markdown
Contributor

cc @ellatrix this feels like a good one to review.

@Mamaduka

Copy link
Copy Markdown
Member

Thanks for the PR, @im3dabasia!

The empty list item bug has the same root cause as #82980 (Preformatted and Poetry, fix proposed in #83552). The "entirely selected" branch from #80994 runs before the splitting check and the canInsertBlockType conversion, so it skips both.

I think we can fix both here by moving that branch to the end of the handler, instead of adding the blocks.every() condition:

// Pasting over an entirely selected block replaces it, the
// equivalent of pasting into an empty block.
if (
	! hasMultiSelection() &&
	isBlockEntirelySelected(
		event.target.ownerDocument,
		firstSelectedClientId
	)
) {
	replaceBlocks(
		selectedBlockClientIds,
		newBlocks,
		newBlocks.length - 1,
		-1
	);
} else {
	__unstableSplitSelection( newBlocks );
}
event.preventDefault();

I haven't tested this. If it works, could you also add an e2e test for pasting multi-line text into an empty Preformatted block? It can go in test/e2e/specs/editor/blocks/preformatted.spec.js.

@Mamaduka

Copy link
Copy Markdown
Member

@im3dabasia, I merged #83552, but I think my suggestion is still valid. Give it a try when you have time.

@im3dabasia

Copy link
Copy Markdown
Contributor Author

I merged #83552, but I think my suggestion is still valid. Give it a try when you have time.

Thanks, @Mamaduka! This is on my priority list. I’ll look into it and test it today. I appreciate the (re)ping! I’ll get this PR into shape as soon as possible and get back to you. Thanks again!

@Mamaduka

Copy link
Copy Markdown
Member

@im3dabasia, no rush. Just wanted to keep you updated, hence the pings :)

@im3dabasia

im3dabasia commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor Author

@im3dabasia, no rush. Just wanted to keep you updated, hence the pings :)

Thanks @Mamaduka, done. Moving the check to the end works for the empty list item.

Attaching some screencast.

Screen.Recording.2026-10-15.at.3.42.42.PM.mov

@im3dabasia

Copy link
Copy Markdown
Contributor Author

Unrelated to this PR: the list item selection outline cuts through the first letter and nested bullets. It happens on trunk too, so I'd leave it out of here. Worth a separate issue?

image image

@im3dabasia

Copy link
Copy Markdown
Contributor Author

Hey @Mamaduka @ellatrix, when you get a chance, please review this PR. Thanks for your time!

@Mamaduka

Copy link
Copy Markdown
Member

Sorry for the late reply, @im3dabasia!

The use-clipboard-handler change looks good, but I don't think we should join innerBlocks in __unstableSplitSelection.

block-editor is block-agnostic, so it can't know how two sets of inner blocks should combine. When both sides have a nested list, the list item ends up with two sibling core/list blocks. Other merge paths avoid this: mergeBlocks and __unstableDeleteSelection don't join inner blocks, and the list item's useMerge moves the items into a single list. Pasting at the end of an item with its own nested list also still deletes that list.

I think a safer default is to merge only blocks without inner blocks, insert the rest whole, and keep the empty tail when it still holds inner blocks.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] List Affects the List Block [Feature] Paste [Package] Block editor /packages/block-editor [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

List block: unable to cut or copy main item if sub-items exist

5 participants