Skip to content

Rich Text loses the custom format on copy/paste #16240

Closed

Description

@OksanaRomaniv

Describe the bug
When copying rich text with custom format applied (added via Format API) into another rich text editor, the custom format is lost.

My custom format wraps the text in tag and adds some attributes (autogenerated href, class, some data attribute, and target).

When I copy the generated link into another paragraph the format is lost and the link is converted into a regular link.

This doesn't happen when you paste same selected text with formatting to Classic block or when you duplicate the Paragraph block.

Registering format call:

(function(wp) {
	// Register Amazon Links Format
	let amazonLinkFormat = 'advents-pro/amazon-link';

	// Register Amazon Link Format
	registerFormatType(amazonLinkFormat, {
		title: 'Amazon Affiliate Link',
		tagName: 'a',
		className: 'amazonLink',
		attributes: {
			href: 'href',
			dataLinkAsin: 'data-link-asin',
			target: 'target',
			rel: 'rel',
		},
		edit: AmazonLinkPopover,
	});
})(window.wp);

Applying format call:

onApplyClick = () => {
	const onChange = this.props.onChange;
		onChange(
			applyFormat(this.props.value, {
				type: amazonLinkFormat,
				attributes: {
					href: this.generateLink(),
					target: '_blank',
					rel: 'nofollow',
					'data-link-asin': this.state.asin,
				},
			})
		);
	this.setState({ asin: '', isEditing: false, isVisible: false });
};

To reproduce
Steps to reproduce the behavior:

  1. Go to a paragraph block
  2. Click on custom format that adds a link tag
  3. Copy text to another paragraph block
  4. See that the format is not copied correctly

Expected behavior
The format information is not lost.

Demonstration
https://drive.google.com/file/d/1abNAhFzWva-WTpc4noLYadVAv2OGmTPU/view?usp=sharing

Desktop (please complete the following information):

  • OS: Ubuntu 18.04.2 LTS
  • Browser : Chrome
  • Version : Version 75.0.3770.80 (Official Build) (64-bit)

Additional context

  • WP version: 5.2.2

Activity

  1. added
    [Package] Format library
    Needs Testing
    on Jun 25, 2019
  2. added
    [Status] Needs More Info
    and removed
    Needs Testing
    on Nov 14, 2019
  3. talldan commented on Nov 14, 2019

    @talldan
    Contributor

    Hi @OksanaRomaniv, thanks for creating the issue and apologies for the delay in a response.

    Is this an issue you're still experiencing? I wasn't able to use your code example as it looks like it's incomplete (AmazonLinkPopover needs to be defined).

    However, I tested with a plugin that registers multiple custom formats (Kioken Blocks) and copy/paste seemed to work.

    One thought is that it might be because the tagName is the same use by the core link format (tagName: 'a'). Would be great if that's something you could help clarify.

  4. OksanaRomaniv commented on Dec 4, 2019

    @OksanaRomaniv
    Author

    Hello @talldan , thank you for the reply!

    This is the AmazonLinkPopover element: https://gist.github.com/OksanaRomaniv/562cc857329eb0aa4d3ab78436e80e65

    It could be connected to the tagname, as the formatting is pasted as a default link format. Is there a way to add your custom format for the same tag without losing copy/paste functionality?

  5. added
    Needs Testing
    and removed
    [Status] Needs More Info
    on Jan 13, 2020
  6. added
    Needs Technical Feedback
    and removed
    Needs Testing
    on Jul 7, 2020
  7. jordesign commented on Aug 4, 2023

    @jordesign
    Contributor

    Hey @OksanaRomaniv - looping back to this thread - do you still see the issue present in testing?

  8. added
    [Status] Needs More Info
    [Type] Bug
    on Aug 4, 2023
  9. ellatrix commented on Aug 15, 2023

    @ellatrix
    Member

    This should have been fixed a while ago by #27967. Please reopen if it's still an issue. :)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs Technical Feedback[Feature] Paste[Package] Format library[Status] Needs More Info[Type] Bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions