Damien Elmes 2018-07-23 12:23:38 +10:00
parent a9f69b329f
commit c3f3a996c5

View file

@ -28,6 +28,14 @@ function saveNow(keepFocus) {
} }
} }
function triggerKeyTimer() {
clearChangeTimer();
changeTimer = setTimeout(function () {
updateButtonState();
saveField("key");
}, 600);
}
function onKey() { function onKey() {
// esc clears focus, allowing dialog to close // esc clears focus, allowing dialog to close
if (window.event.which === 27) { if (window.event.which === 27) {
@ -41,11 +49,7 @@ function onKey() {
focusPrevious(); focusPrevious();
return; return;
} }
clearChangeTimer(); triggerKeyTimer();
changeTimer = setTimeout(function () {
updateButtonState();
saveField("key");
}, 600);
} }
function insertNewline() { function insertNewline() {
@ -82,10 +86,14 @@ function inPreEnvironment() {
return window.getComputedStyle(n).whiteSpace.startsWith("pre"); return window.getComputedStyle(n).whiteSpace.startsWith("pre");
} }
function checkForEmptyField() { function onInput() {
// empty field?
if (currentField.innerHTML === "") { if (currentField.innerHTML === "") {
currentField.innerHTML = "<br>"; currentField.innerHTML = "<br>";
} }
// make sure IME changes get saved
triggerKeyTimer();
} }
function updateButtonState() { function updateButtonState() {
@ -288,7 +296,7 @@ function setFields(fields) {
f = "<br>"; f = "<br>";
} }
txt += "<tr><td class=fname>{0}</td></tr><tr><td width=100%>".format(n); txt += "<tr><td class=fname>{0}</td></tr><tr><td width=100%>".format(n);
txt += "<div id=f{0} onkeydown='onKey();' oninput='checkForEmptyField()' onmouseup='onKey();'".format(i); txt += "<div id=f{0} onkeydown='onKey();' oninput='onInput()' onmouseup='onKey();'".format(i);
txt += " onfocus='onFocus(this);' onblur='onBlur();' class=field "; txt += " onfocus='onFocus(this);' onblur='onBlur();' class=field ";
txt += "ondragover='onDragOver(this);' onpaste='onPaste(this);' "; txt += "ondragover='onDragOver(this);' onpaste='onPaste(this);' ";
txt += "oncopy='onCutOrCopy(this);' oncut='onCutOrCopy(this);' "; txt += "oncopy='onCutOrCopy(this);' oncut='onCutOrCopy(this);' ";