Issue #2908💬 AnsweredOpened July 21, 2020by neon123450 reactions

Combine getDirtyCount with undo/redo

Quick answerby mcottret

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)

mcottretJuly 27, 2020

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...

neon12345July 27, 2020

Ok. But that means undo and redo will always trigger autosave, which is not optimal.

artfAugust 25, 2020

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.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

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.