Repository navigation
Description
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:
- Go to a paragraph block
- Click on custom format that adds a link tag
- Copy text to another paragraph block
- 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
talldan commentedon Nov 14, 2019
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 (
AmazonLinkPopoverneeds 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.OksanaRomaniv commentedon Dec 4, 2019
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?jordesign commentedon Aug 4, 2023
Hey @OksanaRomaniv - looping back to this thread - do you still see the issue present in testing?
ellatrix commentedon Aug 15, 2023
This should have been fixed a while ago by #27967. Please reopen if it's still an issue. :)