wangEditor 修改如何做到默认修改全部内容?

发布于 2022-09-11 19:06:24 字数 1602 浏览 20 评论 0

问题

我使用 wangEditor 来修改简单的几个字,想默认点击工具栏的时修改全部内容

我的思路

在执行命令前判断时候开启了默认修改全部的选项(defaultEditorAll)开启了就全选内容然后执行命令

我的问题

不知道如何全选元素,我尝试了外部方法,可以设置加粗这些,第一次点击有效,第二次就没了

在这个文件 扩展方法全选,或直接在下面的 if (editor.config.defaultEditorAll) 中判断,不知道如何实现全选元素,原生的实现我是,但是提示我 Range 不再 Document 内!!

    // 执行命令
    do: function (name, value) {
        const editor = this.editor;

        // 使用 styleWithCSS
        if (!editor._useStyleWithCSS) {
            document.execCommand('styleWithCSS', null, true);
            editor._useStyleWithCSS = true
        }

        // 如果默认更改全部开启
        if (editor.config.defaultEditorAll) {
            // 这个地方如何做?
        }

        // 如果无选区,忽略
        if (!editor.selection.getRange()) {
            return
        }

        // 恢复选取
        editor.selection.restoreSelection();

        // 执行
        const _name = '_' + name;
        if (this[_name]) {
            // 有自定义事件
            this[_name](value)
        } else {
            // 默认 command
            this._execCommand(name, value)
        }

        // 修改菜单状态
        editor.menus.changeActive();

        // 最后,恢复选取保证光标在原来的位置闪烁
        editor.selection.saveRange();
        editor.selection.restoreSelection();

        // 触发 onchange
        editor.change && editor.change()
    },

原先代码

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文