From 594fc9bebdee7bc40930aad0e0d4b570df2d1453 Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Fri, 29 Jan 2021 00:43:45 +0100 Subject: [PATCH] Fix focus change on tab --- qt/aqt/data/web/js/editor.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/qt/aqt/data/web/js/editor.ts b/qt/aqt/data/web/js/editor.ts index b7ab7306d..a1d2ab0f9 100644 --- a/qt/aqt/data/web/js/editor.ts +++ b/qt/aqt/data/web/js/editor.ts @@ -2,8 +2,8 @@ * License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html */ let currentField: EditingContainer | null = null; -let changeTimer = null; -let currentNoteId = null; +let changeTimer: number | null = null; +let currentNoteId: number | null = null; declare interface String { format(...args: string[]): string; @@ -254,6 +254,7 @@ function onFocus(evt: FocusEvent): void { // anki window refocused; current element unchanged return; } + elem.focusEditingArea(); currentField = elem; pycmd(`focus:${currentFieldOrdinal()}`); enableButtons(); @@ -307,12 +308,12 @@ function onPaste(): void { } function caretToEnd(): void { - const r = document.createRange(); - r.selectNodeContents(currentField); - r.collapse(false); - const s = currentField.getSelection(); - s.removeAllRanges(); - s.addRange(r); + const range = document.createRange(); + range.selectNodeContents(currentField.editingArea); + range.collapse(false); + const selection = currentField.getSelection(); + selection.removeAllRanges(); + selection.addRange(range); } function onBlur(): void {