【问题标题】:Jodit: pasting text that calls the html paste pop up failsJodit:粘贴调用html粘贴弹出的文本失败
【发布时间】:2020-08-29 02:09:24
【问题描述】:

我正在向网页添加 Jodit 编辑器。我希望能够将格式化文本从 MS Word 粘贴到编辑器中。我可以粘贴不会调用用于粘贴 html 文本的小弹出窗口的文本,但不能粘贴带有格式的文本。控制台记录addRange(): The given range isn't in document 的警告。实际上,记录 window.getSelection().rangeCount 返回 0(而不是其他情况下的 1)。我不知道从各种程序粘贴有什么问题,当然,适用于website。我错过了一个活动吗?

【问题讨论】:

    标签: jodit


    【解决方案1】:

    问题在于编辑器位于 ag-grid 单元格中。从 MS Word 粘贴到编辑器时,对话框中的不同选择位于 ag-grid 单元格之外,因此在对话框中单击结束了 ag-grid 会话中期编辑! 由于我正在寻找的行为是保持格式,我只是关闭了对话框(askBeforePasteFromWord: falseaskBeforePasteHTML: false)。为了仍然处理来自 MS Word 的粘贴(因为 MS Word),在 Jodit 的作者的代码中添加到自动处理(https://github.com/xdan/jodit/issues/197):

                  jodit_editor = new Jodit(text_area_element, {
                  hotkeys: {
                      redo: 'ctrl+z',
                      undo: 'ctrl+y,ctrl+shift+z',
                      indent: 'ctrl+]',
                      outdent: 'ctrl+[',
                      bold: 'ctrl+b',
                      italic: 'ctrl+i',
                      removeFormat: 'ctrl+shift+m',
                      insertOrderedList: 'ctrl+shift+7',
                      insertUnorderedList: 'ctrl+shift+8',
                      openSearchDialog: 'ctrl+f',
                      openReplaceDialog: 'ctrl+r',
                  },
                  events: {
                      processPaste: function(event, html){
                          jodit_editor.selection.insertHTML(html);
                          jodit_editor.tempContent = jodit_editor.getEditorValue();
                      },
                      afterPaste: function(event){
                          let el = $('<div></div>');
                          el.html(jodit_editor.tempContent ? jodit_editor.tempContent : jodit_editor.getEditorValue());
                          jodit_editor.setEditorValue(el.html());
                          jodit_editor.tempContent = null;
                      },
                  },
                  askBeforePasteFromWord: false,
                  askBeforePasteHTML: false
    
              });

    【讨论】:

    • 请注意 askBeforePasteFromHTML 应该是 askBeforePasteHTML - 只是解释中的一个错字,您的代码示例是正确的。
    • 谢谢--我编辑了评论以修正那个错字!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-01
    • 2020-11-06
    • 1970-01-01
    • 2016-10-12
    相关资源
    最近更新 更多