Fix dirty when undoing after save

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

25
edit.js
View File

@ -52,7 +52,12 @@ function setCleanItem(node, isClean) {
if (isClean) {
delete dirty[node.id];
// 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 {
dirty[node.id] = true;
}
@ -75,9 +80,8 @@ function setCleanSection(section) {
section.querySelectorAll(".style-contributor").forEach(function(node) { setCleanItem(node, true) });
// #header section has no codemirror
var wrapper = section.querySelector(".CodeMirror");
if (wrapper) {
var cm = wrapper.CodeMirror;
var cm = getCodeMirrorForSection(section)
if (cm) {
section.savedValue = cm.changeGeneration();
indicateCodeChange(cm);
}
@ -225,11 +229,24 @@ function setupCodeMirror(textarea, index) {
}
function indicateCodeChange(cm) {
var section = cm.getTextArea().parentNode;
var section = getSectionForCodeMirror(cm);
setCleanItem(section, cm.isClean(section.savedValue));
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
document.addEventListener("scroll", function(e) {
if (lockScroll && lockScroll.windowScrollY != window.scrollY) {