From 341da7385aa6207a1538700eac9db45d6812415e Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 4 Dec 2017 12:53:28 +1000 Subject: [PATCH] ignore editor shortcuts when no field focused --- aqt/editor.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/aqt/editor.py b/aqt/editor.py index 8793b57f9..5c2d18c29 100644 --- a/aqt/editor.py +++ b/aqt/editor.py @@ -169,8 +169,9 @@ class Editor: ) def setupShortcuts(self): + # if a third element is provided, enable shortcut even when no field selected cuts = [ - ("Ctrl+L", self.onCardLayout), + ("Ctrl+L", self.onCardLayout, True), ("Ctrl+B", self.toggleBold), ("Ctrl+I", self.toggleItalic), ("Ctrl+U", self.toggleUnderline), @@ -189,12 +190,24 @@ class Editor: ("Ctrl+M, M", self.insertMathjaxInline), ("Ctrl+M, E", self.insertMathjaxBlock), ("Ctrl+Shift+X", self.onHtmlEdit), - ("Ctrl+Shift+T", self.onFocusTags) + ("Ctrl+Shift+T", self.onFocusTags, True) ] runHook("setupEditorShortcuts", cuts, self) - for keys, fn in cuts: + for row in cuts: + if len(row) == 2: + keys, fn = row + fn = self._addFocusCheck(fn) + else: + keys, fn, _ = row QShortcut(QKeySequence(keys), self.widget, activated=fn) + def _addFocusCheck(self, fn): + def checkFocus(): + if self.currentField is None: + return + fn() + return checkFocus + def onFields(self): self.saveNow(self._onFields)