Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pasting text into List Block turns it into a Paragraph block #31067

Closed
maddisondesigns opened this issue Apr 22, 2021 · 4 comments
Closed

Pasting text into List Block turns it into a Paragraph block #31067

maddisondesigns opened this issue Apr 22, 2021 · 4 comments
Labels
[Feature] Paste [Type] Bug An existing feature does not function as intended

Comments

@maddisondesigns
Copy link

Description

When you paste plain text into a List Block it turns into a paragraph block!! Why??

Since you refuse to add a Paste as Text button on blocks, I'm quite often forced to paste text into a plain text editor like BBEdit, to remove the formatting first. When I try and paste text into a List block, it turns it into a Paragraph block. The Paragraph Block offers the ability to transform it back into a List Block. This is just ridiculous! I'm already in a List block, so I obviously want the text pasted as a list. You've shown that you have the ability to change this text into a list by the fact that you have that Transform option. Why can't you automatically transform it when I paste it so I don't have to perform an extra unwanted step of converting it back into the block that I actually wanted in the first place! This is not making WordPress easier to use!

Screen+Recording+2021-04-22+at+02.27.39+pm.mp4

Step-by-step reproduction instructions

Expected behaviour

If I paste text into a List Block, I expect it to remain a List Block

Actual behaviour

It changes into a completely different block that I never wanted to use

Screenshots or screen recording (optional)

See vid above

WordPress information

  • WordPress version: 5.7.1
  • Gutenberg version: 10.4.1
  • Are all plugins except Gutenberg deactivated? Yes
  • Are you using a default theme (e.g. Twenty Twenty-One)? TT1 Blocks

Device information

  • Device: Mac
  • Operating system: macOS Big Sur 11.2.3
  • Browser: Firefox 87.0
@vdwijngaert
Copy link
Member

Can confirm this is the case. Looks like the logic to convert the plain text that was in the clipboard turns this input in a paragraph, with each line separated with a line break. This in turn gets converted to a paragraph block, which is probably why the conversion happens.

I've been looking into how the logic that handles pasting in a RichText component works, and so far, my most elegant solution is adding this snippet in packages/blocks/src/api/raw-handling/paste-handler.js, at line 176:

	if (
		mode === 'AUTO' &&
		( tagName === 'ul' || tagName === 'ol' ) &&
		pieces.length === 1
	) {
		return filterInlineHTML( pieces[ 0 ], preserveWhiteSpace );
	}

Although it fixes the issue we're facing here, I'm not sure this is the best way to approach this though. At this stage, I'm not familiar enough with the ins and out of this part of Gutenberg, but there might be a more elegant solution using the transforms on the List block.

@kathrynwp
Copy link

I can still replicate this with:

WordPress 6.0.1
Gutenberg 13.8.2 active or inactive
No other plugins active

Twenty Twenty-Two 1.2

@ironprogrammer
Copy link
Contributor

Reproduction Report

This issue appears to have been resolved. Recommend Close if it cannot still be reproduced.

Environment

  • Hardware: MacBook Pro Apple M1 Pro
  • OS: macOS 12.6.3
  • Browser: Safari 16.3, Google Chrome 110.0.5481.177, Mozilla Firefox 109.0.1
  • Server: nginx/1.23.3
  • PHP: 7.4.33
  • WordPress: 6.1.1, 6.2-beta4
  • Theme: twentytwentytwo v1.3
  • Active Plugins:
    • gutenberg v15.2.4 (both active and inactive)

Actual Results

  • ❌ Could not reproduce in Chrome, Firefox, or Safari on macOS: pasted multi-line text is converted to list items as expected.

Supplemental Artifacts

Demo showing multi-line text converted to list items on paste.
Figure 1: Pasting multi-line plain text from Sublime Text is converted to List block items, as expected.

@maddisondesigns
Copy link
Author

@ironprogrammer Can confirm that this appears to be fixed now. Thanks.

Just tested with WP 6.1.1 (Core only) and also with the Gutenberg (v15.2.4) plugin enabled. I can now paste a list into an actual List block without it converting back to some unwanted block. I'll close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Paste [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

5 participants