阻止 undo() 清除编辑器 Quill / QuillJS 中的所有内容?

Stop undo() from clearing everything in the editor Quill / QuillJS?

我创建了一种将 Quill 文本保存到数据库的方法。每次用户单击已保存的文档时,它都会从数据库中提取已保存的 Quill 文本,并将文本显示在 Quill 文本编辑器中。此时,如果我触发撤消功能,它将删除所有从数据库中提取的文本,因此页面是空白的。

我认为发生的事情是 Quill 编辑器将从数据库中提取的文本视为粘贴到文本编辑器中,因此当您触发撤消功能时,它会清除 "paste/pull from the database"。

有没有办法阻止这种情况发生?在从数据库中提取初始文本后立即触发撤消功能时,有没有办法让 quill 不清除所有内容?

当您 "load" 将数据库中的内容输入编辑器时,无论您喜欢与否,您都在更改 Quill Delta 中的内容(数据)。对 Quill 的内容所做的任何类型的更改本身都被视为......嗯......所做的更改因此可以撤消。

[...] Every time a user clicks on a saved document, it pulls the saved Quill text from the database and has the text appear within the Quill text editor. At this point, if I trigger the undo function, it will delete ALL the text pulled from the database, so the page is blank. [...] Is there a way to stop this from happening? Is there a way to make quill NOT clear everything when you trigger the undo function right after pulling the initial text from the database?

由于您刚刚向 Quill 添加内容并且没有兴趣担心您之前所做的任何更改,我建议您看一下 this。基本上,这个想法是:

  1. 获取内容。
  2. 将其添加到编辑器中。
  3. 添加完成后,调用如下代码:
quill.history.clear();

之后,当尝试执行撤消操作时,将不会发生任何事情,因为没有存储历史记录。

创建 Quill 对象时,在您的模块中设置历史配置。例如:

var quill = new Quill('#editor', {
  modules: {
    history: {
      delay: 2000,
      maxStack: 500,
      userOnly: true
    }
  },
  theme: 'snow'
});

“userOnly”配置将以编程方式过滤掉值更改。

https://quilljs.com/docs/modules/history/#useronly