Combine getDirtyCount with undo/redo
Hi @neon12345 ! As far as I know, the changesCount is also used in conjunction with stepsBeforeSave to trigger storing when autosave is enabled. (cf: https://grapesjs.com/docs/modules/Storage.html#store-and-load-templateshttps://github.com/artf/grapesjs/blob/dev/src/editor/model/Editor.js#L170 ) Cheers !
Read full answer below ↓Question
Currently the changesCount is only increased regardless of undo and redo. I wonder if there is an application where the actual value is used or if this is just a boolean indicator for changes. If it is just used as boolean, it would be possible to instead add a flag to the undo state and mark the saved position. This way it is possible to signal changes only when the undo stack does not point to the saved position on undo and redo. Something like this seems to work: var um = editor.UndoManager; var changepoint = null; var hasChange = false; function findChange() { var s = um.getStack(); var i...
Answers (3)
Hi @neon12345 ! As far as I know, the changesCount is also used in conjunction with stepsBeforeSave to trigger storing when autosave is enabled. (cf: https://grapesjs.com/docs/modules/Storage.html#store-and-load-templateshttps://github.com/artf/grapesjs/blob/dev/src/editor/model/Editor.js#L170 ) Ch...
Ok. But that means undo and redo will always trigger autosave, which is not optimal.
getDirtyCount returns the number of changes, so it's not used as a boolean. If you have a better solution to handle undo/redo changes the PR is welcome
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1888
[Question] Add custom html inside canvas
Hi there, I'm using grapes to export a custom json with all the information i need, instead of HTML and CSS. For doing that I'm parsing the...
Issue #1047
[BUG] Model not able to change after changing value in custom Select dropdown menu.
Hey, I'm using CDN link for grapes js from unpkg.com In my project, I've used custom trait as a drop-down select menu which changes HTML us...
Issue #1708
StyleManager events fire multiple times per change
To reproduce: On a fresh install of GrapesJS, within the demo page (within index.html), add an event listener like so: editor.on('component...
Issue #2008
[Question]The canvas turns dark and unmodifiable on adding a large piece of custom html.
I used to add custom html with editor.addComponent(). It works well at most of the time, but when I try to insert a large piece of HTML whi...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins →Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.
Browse premium plugins →Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.