mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Explode onBridgeCmd
This way, an add-on can catch a blur command, do its change and then call self.blur
This commit is contained in:
parent
beee1f10e0
commit
9f4c4ea355
1 changed files with 47 additions and 36 deletions
|
@ -367,8 +367,20 @@ class Editor:
|
||||||
# shutdown
|
# shutdown
|
||||||
return
|
return
|
||||||
# focus lost or key/button pressed?
|
# focus lost or key/button pressed?
|
||||||
if cmd.startswith("blur") or cmd.startswith("key"):
|
type, remaining = cmd.split(":", 1)
|
||||||
(type, ord, nid, txt) = cmd.split(":", 3)
|
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)
|
||||||
|
else:
|
||||||
|
print("uncaught cmd", cmd)
|
||||||
|
|
||||||
|
def onBlurOrKey(self, ord, nid, txt):
|
||||||
ord = int(ord)
|
ord = int(ord)
|
||||||
try:
|
try:
|
||||||
nid = int(nid)
|
nid = int(nid)
|
||||||
|
@ -387,27 +399,26 @@ class Editor:
|
||||||
if not self.addMode:
|
if not self.addMode:
|
||||||
self.note.flush()
|
self.note.flush()
|
||||||
self.mw.requireReset()
|
self.mw.requireReset()
|
||||||
if type == "blur":
|
|
||||||
|
def onBlur(self, ord, nid, txt):
|
||||||
|
self.onBlurOrKey(ord, nid, txt)
|
||||||
self.currentField = None
|
self.currentField = None
|
||||||
# run any filters
|
# run any filters
|
||||||
if gui_hooks.editor_did_unfocus_field(False, self.note, ord):
|
if gui_hooks.editor_did_unfocus_field(False, self.note, int(ord)):
|
||||||
# something updated the note; update it after a subsequent focus
|
# something updated the note; update it after a subsequent focus
|
||||||
# event has had time to fire
|
# event has had time to fire
|
||||||
self.mw.progress.timer(100, self.loadNoteKeepingFocus, False)
|
self.mw.progress.timer(100, self.loadNoteKeepingFocus, False)
|
||||||
else:
|
else:
|
||||||
self.checkValid()
|
self.checkValid()
|
||||||
else:
|
|
||||||
|
def onKey(self, ord, nid, txt):
|
||||||
|
self.onBlurOrKey(ord, nid, txt)
|
||||||
gui_hooks.editor_did_fire_typing_timer(self.note)
|
gui_hooks.editor_did_fire_typing_timer(self.note)
|
||||||
self.checkValid()
|
self.checkValid()
|
||||||
# focused into field?
|
|
||||||
elif cmd.startswith("focus"):
|
def onFocus(self, num):
|
||||||
(type, num) = cmd.split(":", 1)
|
|
||||||
self.currentField = int(num)
|
self.currentField = int(num)
|
||||||
gui_hooks.editor_did_focus_field(self.note, self.currentField)
|
gui_hooks.editor_did_focus_field(self.note, self.currentField)
|
||||||
elif cmd in self._links:
|
|
||||||
self._links[cmd](self)
|
|
||||||
else:
|
|
||||||
print("uncaught cmd", cmd)
|
|
||||||
|
|
||||||
def mungeHTML(self, txt):
|
def mungeHTML(self, txt):
|
||||||
if txt in ("<br>", "<div><br></div>"):
|
if txt in ("<br>", "<div><br></div>"):
|
||||||
|
|
Loading…
Reference in a new issue