From c3f3a996c59a7ec0b0a0a76401880fe669983868 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 23 Jul 2018 12:23:38 +1000 Subject: [PATCH] fix changes made in Windows IME not being saved https://anki.tenderapp.com/discussions/ankidesktop/28727-last-japanese-edit-in-a-field-doesnt-take-unless-enter-is-pressed-an-extra-time --- web/editor.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/web/editor.js b/web/editor.js index d5d0309e7..9b30ac119 100644 --- a/web/editor.js +++ b/web/editor.js @@ -28,6 +28,14 @@ function saveNow(keepFocus) { } } +function triggerKeyTimer() { + clearChangeTimer(); + changeTimer = setTimeout(function () { + updateButtonState(); + saveField("key"); + }, 600); +} + function onKey() { // esc clears focus, allowing dialog to close if (window.event.which === 27) { @@ -41,11 +49,7 @@ function onKey() { focusPrevious(); return; } - clearChangeTimer(); - changeTimer = setTimeout(function () { - updateButtonState(); - saveField("key"); - }, 600); + triggerKeyTimer(); } function insertNewline() { @@ -82,10 +86,14 @@ function inPreEnvironment() { return window.getComputedStyle(n).whiteSpace.startsWith("pre"); } -function checkForEmptyField() { +function onInput() { + // empty field? if (currentField.innerHTML === "") { currentField.innerHTML = "
"; } + + // make sure IME changes get saved + triggerKeyTimer(); } function updateButtonState() { @@ -288,7 +296,7 @@ function setFields(fields) { f = "
"; } txt += "{0}".format(n); - txt += "