From 954c5171e32d008346e77fc8636c903a3cbc514d Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 24 Apr 2012 08:27:40 +0900 Subject: [PATCH] focus correct field on tab/backtab --- aqt/editor.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/aqt/editor.py b/aqt/editor.py index 1703c86d0..63985a10c 100644 --- a/aqt/editor.py +++ b/aqt/editor.py @@ -119,6 +119,10 @@ function onFocus(elem) { } } +function focusField(n) { + $("#f"+n).focus(); +} + function onDragOver(elem) { elem.focus(); } @@ -894,6 +898,14 @@ class EditorWebView(AnkiWebView): else: AnkiWebView.mouseReleaseEvent(self, evt) + def focusInEvent(self, evt): + AnkiWebView.focusInEvent(self, evt) + if evt.reason() == Qt.TabFocusReason: + self.eval("focusField(0);") + elif evt.reason() == Qt.BacktabFocusReason: + n = len(self.editor.note.fields) - 1 + self.eval("focusField(%d);" % n) + # Buggy; disable for now. # def contextMenuEvent(self, evt): # # adjust in case the user is going to paste