Inserting content through an extension causes a duplication issue.
See original GitHub issueHi, I’m working on a chrome extension that lets you input text through it. Unfortunately Draft.js breaks when inputting in a standard way.
Steps to reproduce:
- Load http://facebook.github.io/draft-js/
- Open Chrome Dev Tools
- Select the Draft.js input box so that the input caret is present
- execute
document.execCommand("insertHTML", false, "X");
in the dev tools console
Result expected:
X
is added to the input box
Actual result:
X
is added to the input box twice. You’re able to delete one of the instances, but the other one is undeletable but is selectable.
Note: Once at least one character has been typed into the Draft.js input the command works as expected.
Screenshot of the result:
Issue Analytics
- State:
- Created 8 years ago
- Reactions:1
- Comments:10 (1 by maintainers)
Top Results From Across the Web
Inserting text with execCommand causes a duplication issue
I'm working on a Firefox extension that inserts Polish characters to any text field using keyboard shortcuts. It's working for all text ......
Read more >Seeing Double: Your SEO Guide to Duplicate Content
Duplicate content is an incredibly common SEO issue. But what is it? Why is it bad? And what can you do about it?...
Read more >How To Identify And Fix Duplicate Content Issues With SEO ...
The detailed guide on how to identify and fix duplicate content issues. You'll learn what duplicate content is, why it occurs, and how...
Read more >Duplicate Content: 5 Myths and 5 Facts About How It Impacts ...
“Duplicate content on a site is not grounds for action on that site unless it appears that the intent of the duplicate content...
Read more >Duplicate Content: Why does it happen and how to fix issues
Duplicate content is content that appears on the Internet in more than one place. That “one place” is defined as a location with...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Here’s the code:
if (document.querySelectorAll('span[data-text="true"]').length === 0) {
document.execCommand("insertHTML", false, "X");
document.execCommand("undo", false);
} else {
document.execCommand("insertHTML", false, "X");
}
It will check to see if you have entered the first character. If you did, it’ll do the undo execCommand and remove the extra X. The
else
will just insertHTML since it won’t insert any extras once characters have been entered.Looks like a workaround was found, so I’m going to close this out.