fire saveField("key") when webview loses focus

fixes the following reported issue, caused by currentField
being sent to None:

1. Start from the main view.
2. Click Add
3. In the Add window, change deck
4. In the Choose Deck window, add a new deck, give a random name
5. Back in the Add window, call "Edit HTML"
6. Anki displays an error

This change will mean the editFocusLost hook will not fire when
switching between windows, which is probably an improvement.
This commit is contained in:
Damien Elmes 2019-02-05 10:46:47 +10:00
parent 1675d2f01e
commit dd01561537

View File

@ -24,6 +24,7 @@ function saveNow(keepFocus) {
if (keepFocus) {
saveField("key");
} else {
// triggers onBlur, which saves
currentField.blur();
}
}
@ -207,28 +208,28 @@ function caretToEnd() {
}
function onBlur() {
if (currentField) {
saveField("blur");
clearChangeTimer();
if (!currentField) {
return;
}
if (document.activeElement === currentField) {
// other widget or window focused; current field unchanged
return;
saveField("key");
} else {
saveField("blur");
currentField = null;
disableButtons();
}
currentField = null;
disableButtons();
}
function saveField(type) {
clearChangeTimer();
if (!currentField) {
// no field has been focused yet
return;
}
// type is either 'blur' or 'key'
pycmd(type + ":" + currentFieldOrdinal() + ":" + currentNoteId + ":" + currentField.innerHTML);
clearChangeTimer();
}
function currentFieldOrdinal() {