BUG: Problem with copy and paste a node
Question
**Version:0.16.27
Are you able to reproduce the bug from the demo?
[ * ] Yes [ ] No
What is the expected behavior? In the right panel and canvas, the pasted node should be after the copied node.
What is the current behavior?
I copy a node. In the views-container(right panel), the pasted node is after the copied node. But in the canvas, the pasted node is before the copied node. As shown below:

Describe the bug detailed
This bug occurs when there are spaces or carriage returns between html tags.
Because in the ‘grapesjs/src/dom_components/view/ComponentsView.js’,addToCollection Method uses js childNodes to get the child nodes.

In the Chrome browser, in addition to the complete label as a node, the content between the ending character ">" of one label and the starting character "<" of the next label (except comments, including any text, Spaces, carriage returns, tabs) are also considered a node.
Are you able to attach screenshots, screencasts or a live demo? bug.mov.zip
Can sombody help with this? Thank you very much!
Answers (3)
I've tried locally but the node is placed correctly. Are you able to create a live demo, please?
Sorry, I did not elaborate on the scenario where this error occurred. The components that come with grapesjs do not produce this error, because they don‘t have spaces,carriage returns or tabs. I found this problem while customizing components. I have customized a lot of my own components, and some of them will have this situation. An example of the initialization of the custom component node that found this problem is as follows.
viewTemplate() {
return '
<form data-gjs-type="form-panel" class="form-panel">
</form>
'
},
...
onViewInit() {
const comps = this.model.get('components');
if (!comps.length) {
comps.reset();
comps.add('
<div class="form-panel-group" data-gjs-type="form-panel-group"><label class="label">多/单选:</label><div data-gjs-type="select-comp" class="select-comp"></div></div>
<div class="form-panel-group" data-gjs-type="form-panel-group"><label class="label">多选选择:</label><div data-gjs-type="mdc-checkbox-group" class="mdc-checkbox-group"></div></div>
</div>
')
}
...
}
If you want to reproduce this problem in the grapesjs default component, you can enter a space between nodes through the “Editor as HTML” of the f12 Elements . as follows.

@artf I accidentally closed the issue.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #3131
BUG: Paste as plain text into Text component adds <font /> wrapper to pasted text
Version: 0.16.27 Are you able to reproduce the bug from the demo? [] Yes [X] No What is the expected behavior? Paste as plain text (text no...
Issue #3063
BUG: Block Highlight Display Bug
Version: 0.6.18 You can get the version by typing grapesjs.version into the console Are you able to reproduce the bug from the demo? [ ] Ye...
Issue #3352
BUG: Default Content is getting Inserted while using setComponents if Tag Body is empty
Version: Latest You can get the version by typing grapesjs.version into the console Are you able to reproduce the bug from the demo?[X] Yes...
Issue #3005
BUG: Layer manager appendTo is duplicating the layers every time grapesjs is init
Version: 0.16.18 and up (The issue was introduced somewhere after 0.15.3, not sure when) Are you able to reproduce the bug from the demo? [...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.