Skip to content

自定义ModalMenu调用api不生效 #6100

@LwcStrong

Description

@LwcStrong

问题描述

请输入遇到的问题...

wangEditor 版本

v5+

    confirmBtn.addEventListener('click', (e) => {
      e.preventDefault();
      const inputValue = input.value.trim();
      const selection = editor.getSelectionText();
      if (inputValue === '') {
        return;
      }
      const node = SlateEditor.nodes(editor);
      console.log('🚀 ~ MyModalMenu ~ getModalContentElem ~ node:', node);
      editor.clear();
      const styledNode = {
        type: 'span', // inline 节点类型(v5 支持 span 原生标签)
        style: {
          color: 'red !important',
          textDecoration: 'underline !important',
        },
        children: [{ text: '12333' }], // 必须包含 text 子节点(v5 文本节点规范)
      };
      editor.hidePanelOrModal();
      // editor.deleteFragment();

      // 第二步:在原选区位置插入带样式节点(v5 正确 API:insertNode)
      editor.insertNode(styledNode);
      // editor.restoreSelection(); // 恢复选区
      // editor.insertText(' ');
    });

自定义了一个弹窗菜单 去给选中文本添加下滑虚线,支持设置虚线的粗细,给弹窗提交按钮绑定了事件,但是调用了文档上的api 大多都不生效,比如 addMark, editor.deleteFragment();等等,上面这段代码是按钮点击回调事件,看看是什么原因引起的。。。。

是否查阅了文档 ?

(文档链接 www.wangeditor.com

最小成本的复现步骤

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions