Reputation: 765
I created a way to save Quill text to a database. 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.
I think what is happening is that the Quill editor sees the pulled up text from the database as a paste into the text editor, so when you trigger the undo function, it clears the "paste/pull from the database".
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?
Upvotes: 2
Views: 3949
Reputation: 186
When creating Quill object, set history config in your modules. For example:
var quill = new Quill('#editor', {
modules: {
history: {
delay: 2000,
maxStack: 500,
userOnly: true
}
},
theme: 'snow'
});
The "userOnly" config will filter out programatically value changes.
https://quilljs.com/docs/modules/history/#useronly
Upvotes: 3
Reputation: 2240
When you "load" the content from the database into the editor, whether you like it or not, you are changing whats inside Quill Delta (the data). Any kind of change made to Quill's content is viewed by itself as... well... a change made, therefore, something that can be undone.
[...] 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?
Since you just added content to Quill and there is no interest in worrying about any changes you made previously, I suggest you take a look at this. Basically, the idea is:
quill.history.clear();
After that, when trying to perform an undo operation, nothing will happen as no history has been stored.
Upvotes: 6