wangeditor-team / wangEditor

wangEditor —— 开源 Web 富文本编辑器
http://www.wangeditor.com/
MIT License
17.37k stars 3.31k forks source link

使用editor.insertNode 后,会自动在头部插入一个空段落节点 #5201

Open darrenwu opened 1 year ago

darrenwu commented 1 year ago

bug 描述

使用editor.insertNode 后,会自动在头部插入一个空段落节点

你预期的样子是?

无需自动在头部插入一个空段落节点

系统和浏览器及版本号

wangEditor 版本

"@wangeditor/editor": "^5.1.23",
"@wangeditor/editor-for-vue": "^5.1.12",

demo 能否复现该 bug ?

在线 demo

https://codesandbox.io/embed/happy-gates-02cl3h?fontsize=14&hidenavigation=1&theme=dark

最小成本的复现步骤

editor初始化后直接inertNode即可 const node = { type: "paragraph", children: [{ text: "simple text" }] }; editor.insertNode(node);

可看在线demo

giligiliduang commented 1 year ago

我在做的项目测试因为这个问题还给我提了个bug

Richlee2016 commented 1 year ago

我在做的项目测试因为这个问题还给我提了个bug 这个我也遇到了,最后解决的办法是 Transforms.insertNodes(editor as any, schema, { at: [0] }); 在初始位子插入即可

giligiliduang commented 1 year ago

我在做的项目测试因为这个问题还给我提了个bug 这个我也遇到了,最后解决的办法是 Transforms.insertNodes(editor as any, schema, { at: [0] }); 在初始位子插入即可

我按照你这个方法确实是在头部插入了节点,但是会在尾部生成一个空行,感觉这块还是有问题

Yutianyudaodao commented 1 year ago

我想要插入这样一个结构的内容

...
,数据是这样的this.editor.insertNode({type: 'goodscard',img,title,price,id,children: [{ text: '' }]}),但插入后会报异常Cannot resolve a DOM node from Slate node: {"text":""},这怎么弄啊

zwf021123 commented 3 months ago

这个问题还没解决吗?