From 14c2fdbb5886ee96f14367e660736e2a8ed3edb9 Mon Sep 17 00:00:00 2001 From: eight Date: Sun, 14 Oct 2018 16:36:12 +0800 Subject: [PATCH] Fix: dirty state for new added applies --- edit/sections-editor-section.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/edit/sections-editor-section.js b/edit/sections-editor-section.js index 087e231c..74540e79 100644 --- a/edit/sections-editor-section.js +++ b/edit/sections-editor-section.js @@ -329,10 +329,10 @@ function createSection({ if (selectEl) { selectEl.value = type; selectEl.addEventListener('change', () => { - const oldKey = type; + const oldType = type; dirty.modify(`${dirtyPrefix}.type`, type, selectEl.value); type = selectEl.value; - if (oldKey === 'regexp' || type === 'regexp') { + if (oldType === 'regexp' || type === 'regexp') { updateRegexpTester(); } emitSectionChange(); @@ -354,6 +354,8 @@ function createSection({ valueEl.addEventListener('change', validate); } + restore(); + const apply = { id: applyId, all, @@ -362,7 +364,7 @@ function createSection({ el, getType: () => type, getValue: () => value, - valueEl + valueEl // used by validator }; const removeButton = $('.remove-applies-to', el); @@ -389,11 +391,17 @@ function createSection({ } function remove() { + if (all) { + return; + } dirty.remove(`${dirtyPrefix}.type`, type); dirty.remove(`${dirtyPrefix}.value`, value); } function restore() { + if (all) { + return; + } dirty.add(`${dirtyPrefix}.type`, type); dirty.add(`${dirtyPrefix}.value`, value); }