Fix dirty when undoing after save

This commit is contained in:
Jason 2015-04-08 13:24:26 -05:00
parent 6abc261f90
commit f8c0c5bf80

27
edit.js
View File

@ -52,7 +52,12 @@ function setCleanItem(node, isClean) {
if (isClean) { if (isClean) {
delete dirty[node.id]; delete dirty[node.id];
node.savedValue = "checkbox" === node.type ? node.checked : node.value; // A div would indicate a section
if (node.nodeName.toLowerCase() == "div") {
node.savedValue = getCodeMirrorForSection(node).changeGeneration();
} else {
node.savedValue = "checkbox" === node.type ? node.checked : node.value;
}
} else { } else {
dirty[node.id] = true; dirty[node.id] = true;
} }
@ -75,9 +80,8 @@ function setCleanSection(section) {
section.querySelectorAll(".style-contributor").forEach(function(node) { setCleanItem(node, true) }); section.querySelectorAll(".style-contributor").forEach(function(node) { setCleanItem(node, true) });
// #header section has no codemirror // #header section has no codemirror
var wrapper = section.querySelector(".CodeMirror"); var cm = getCodeMirrorForSection(section)
if (wrapper) { if (cm) {
var cm = wrapper.CodeMirror;
section.savedValue = cm.changeGeneration(); section.savedValue = cm.changeGeneration();
indicateCodeChange(cm); indicateCodeChange(cm);
} }
@ -225,11 +229,24 @@ function setupCodeMirror(textarea, index) {
} }
function indicateCodeChange(cm) { function indicateCodeChange(cm) {
var section = cm.getTextArea().parentNode; var section = getSectionForCodeMirror(cm);
setCleanItem(section, cm.isClean(section.savedValue)); setCleanItem(section, cm.isClean(section.savedValue));
updateTitle(); updateTitle();
} }
function getSectionForCodeMirror(cm) {
return cm.getTextArea().parentNode;
}
function getCodeMirrorForSection(section) {
// #header section has no codemirror
var wrapper = section.querySelector(".CodeMirror");
if (wrapper) {
return wrapper.CodeMirror;
}
return null;
}
// ensure the section doesn't jump when clicking selected text // ensure the section doesn't jump when clicking selected text
document.addEventListener("scroll", function(e) { document.addEventListener("scroll", function(e) {
if (lockScroll && lockScroll.windowScrollY != window.scrollY) { if (lockScroll && lockScroll.windowScrollY != window.scrollY) {