Löschen/Deaktiveunrg
This commit is contained in:
@@ -155,13 +155,37 @@ export function initEditor() {
|
||||
|
||||
function attachGjsDirtyTracker(editor) {
|
||||
if (!editor || typeof editor.on !== 'function') return () => {};
|
||||
const onUpdate = () => markDirty();
|
||||
let selectionJustChanged = false;
|
||||
let selectionTimer = null;
|
||||
const onSelect = () => {
|
||||
selectionJustChanged = true;
|
||||
if (selectionTimer) clearTimeout(selectionTimer);
|
||||
selectionTimer = setTimeout(() => {
|
||||
selectionJustChanged = false;
|
||||
selectionTimer = null;
|
||||
}, 120);
|
||||
};
|
||||
const onUpdate = () => {
|
||||
if (selectionJustChanged) return;
|
||||
markDirty();
|
||||
};
|
||||
const onComponentUpdate = (model) => {
|
||||
const changed = (model && typeof model.changedAttributes === 'function')
|
||||
? model.changedAttributes()
|
||||
: (model && model.changed) ? model.changed : null;
|
||||
const keys = changed ? Object.keys(changed) : [];
|
||||
if (keys.length === 1 && keys[0] === 'status') return;
|
||||
if (selectionJustChanged && keys.length === 0) return;
|
||||
markDirty();
|
||||
};
|
||||
editor.on('update', onUpdate);
|
||||
editor.on('component:update', onUpdate);
|
||||
editor.on('component:update', onComponentUpdate);
|
||||
editor.on('component:selected', onSelect);
|
||||
return () => {
|
||||
try {
|
||||
editor.off('update', onUpdate);
|
||||
editor.off('component:update', onUpdate);
|
||||
editor.off('component:update', onComponentUpdate);
|
||||
editor.off('component:selected', onSelect);
|
||||
} catch {}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user