mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
Ensure that focus, key and blur are treated as other commands
The reason to do that is that I can then call blur/key from other method in add-on. More precisely, I expect to create a method which captures the blur command, ask anki to execute the standard version of the command, and then execute more code once the note contains the new field value. I should note that the code executed during blur/key/focus itself didn't change. It's only it's location which changed.
This commit is contained in:
parent
9f4c4ea355
commit
c9496ef095
1 changed files with 17 additions and 17 deletions
|
@ -367,20 +367,16 @@ class Editor:
|
|||
# shutdown
|
||||
return
|
||||
# focus lost or key/button pressed?
|
||||
type, remaining = cmd.split(":", 1)
|
||||
if type == "blur":
|
||||
self.onBlur(*remaining.split(":", 2))
|
||||
elif type == "key":
|
||||
self.onKey(*remaining.split(":", 2))
|
||||
# focused into field?
|
||||
elif type == "focus":
|
||||
self.onFocus(remaining)
|
||||
elif cmd in self._links:
|
||||
self._links[cmd](self)
|
||||
splitted = cmd.split(":", 1)
|
||||
cmd = splitted[0]
|
||||
args = splitted[1:]
|
||||
if cmd in self._links:
|
||||
self._links[cmd](self, *args) # type: ignore
|
||||
else:
|
||||
print("uncaught cmd", cmd)
|
||||
|
||||
def onBlurOrKey(self, ord, nid, txt):
|
||||
def onBlurOrKey(self, args):
|
||||
ord, nid, txt = args.split(":", 2)
|
||||
ord = int(ord)
|
||||
try:
|
||||
nid = int(nid)
|
||||
|
@ -399,9 +395,10 @@ class Editor:
|
|||
if not self.addMode:
|
||||
self.note.flush()
|
||||
self.mw.requireReset()
|
||||
return ord
|
||||
|
||||
def onBlur(self, ord, nid, txt):
|
||||
self.onBlurOrKey(ord, nid, txt)
|
||||
def onBlur(self, args):
|
||||
ord = self.onBlurOrKey(args)
|
||||
self.currentField = None
|
||||
# run any filters
|
||||
if gui_hooks.editor_did_unfocus_field(False, self.note, int(ord)):
|
||||
|
@ -411,14 +408,14 @@ class Editor:
|
|||
else:
|
||||
self.checkValid()
|
||||
|
||||
def onKey(self, ord, nid, txt):
|
||||
self.onBlurOrKey(ord, nid, txt)
|
||||
def onKey(self, args):
|
||||
self.onBlurOrKey(args)
|
||||
gui_hooks.editor_did_fire_typing_timer(self.note)
|
||||
self.checkValid()
|
||||
|
||||
def onFocus(self, num):
|
||||
self.currentField = int(num)
|
||||
gui_hooks.editor_did_focus_field(self.note, self.currentField)
|
||||
self.currentField = int(num)
|
||||
gui_hooks.editor_did_focus_field(self.note, self.currentField)
|
||||
|
||||
def mungeHTML(self, txt):
|
||||
if txt in ("<br>", "<div><br></div>"):
|
||||
|
@ -981,6 +978,9 @@ to a cloze type first, via Edit>Change Note Type."""
|
|||
dupes=showDupes,
|
||||
paste=onPaste,
|
||||
cutOrCopy=onCutOrCopy,
|
||||
blur=onBlur,
|
||||
focus=onFocus,
|
||||
key=onKey,
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue