mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
Revert "Merge pull request #527 from Arthur-Milchior/explode_on_bridge_cmd"
This reverts commit2264fe3f66
, reversing changes made to84b84ae31c
. Causes a traceback when opening the add screen, clicking on Type, and choosing a note type. File "/Users/dae/Work/code/dtop/qt/aqt/webview.py", line 31, in cmd return json.dumps(self.onCmd(str)) File "/Users/dae/Work/code/dtop/qt/aqt/webview.py", line 97, in _onCmd return self._onBridgeCmd(str) File "/Users/dae/Work/code/dtop/qt/aqt/webview.py", line 500, in _onBridgeCmd return self.onBridgeCmd(cmd) File "/Users/dae/Work/code/dtop/qt/aqt/editor.py", line 374, in onBridgeCmd self._links[cmd](self, *args) # type: ignore File "/Users/dae/Work/code/dtop/qt/aqt/editor.py", line 404, in onBlur if gui_hooks.editor_did_unfocus_field(False, self.note, int(ord)): TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
This commit is contained in:
parent
158ce7bc01
commit
47bd6264bd
1 changed files with 39 additions and 50 deletions
|
@ -367,56 +367,48 @@ class Editor:
|
||||||
# shutdown
|
# shutdown
|
||||||
return
|
return
|
||||||
# focus lost or key/button pressed?
|
# focus lost or key/button pressed?
|
||||||
splitted = cmd.split(":", 1)
|
if cmd.startswith("blur") or cmd.startswith("key"):
|
||||||
cmd = splitted[0]
|
(type, ord, nid, txt) = cmd.split(":", 3)
|
||||||
args = splitted[1:]
|
ord = int(ord)
|
||||||
if cmd in self._links:
|
try:
|
||||||
self._links[cmd](self, *args) # type: ignore
|
nid = int(nid)
|
||||||
|
except ValueError:
|
||||||
|
nid = 0
|
||||||
|
if nid != self.note.id:
|
||||||
|
print("ignored late blur")
|
||||||
|
return
|
||||||
|
txt = unicodedata.normalize("NFC", txt)
|
||||||
|
txt = self.mungeHTML(txt)
|
||||||
|
# misbehaving apps may include a null byte in the text
|
||||||
|
txt = txt.replace("\x00", "")
|
||||||
|
# reverse the url quoting we added to get images to display
|
||||||
|
txt = self.mw.col.media.escapeImages(txt, unescape=True)
|
||||||
|
self.note.fields[ord] = txt
|
||||||
|
if not self.addMode:
|
||||||
|
self.note.flush()
|
||||||
|
self.mw.requireReset()
|
||||||
|
if type == "blur":
|
||||||
|
self.currentField = None
|
||||||
|
# run any filters
|
||||||
|
if gui_hooks.editor_did_unfocus_field(False, self.note, ord):
|
||||||
|
# something updated the note; update it after a subsequent focus
|
||||||
|
# event has had time to fire
|
||||||
|
self.mw.progress.timer(100, self.loadNoteKeepingFocus, False)
|
||||||
|
else:
|
||||||
|
self.checkValid()
|
||||||
|
else:
|
||||||
|
gui_hooks.editor_did_fire_typing_timer(self.note)
|
||||||
|
self.checkValid()
|
||||||
|
# focused into field?
|
||||||
|
elif cmd.startswith("focus"):
|
||||||
|
(type, num) = cmd.split(":", 1)
|
||||||
|
self.currentField = int(num)
|
||||||
|
gui_hooks.editor_did_focus_field(self.note, self.currentField)
|
||||||
|
elif cmd in self._links:
|
||||||
|
self._links[cmd](self)
|
||||||
else:
|
else:
|
||||||
print("uncaught cmd", cmd)
|
print("uncaught cmd", cmd)
|
||||||
|
|
||||||
def onBlurOrKey(self, args):
|
|
||||||
ord, nid, txt = args.split(":", 2)
|
|
||||||
ord = int(ord)
|
|
||||||
try:
|
|
||||||
nid = int(nid)
|
|
||||||
except ValueError:
|
|
||||||
nid = 0
|
|
||||||
if nid != self.note.id:
|
|
||||||
print("ignored late blur")
|
|
||||||
return
|
|
||||||
txt = unicodedata.normalize("NFC", txt)
|
|
||||||
txt = self.mungeHTML(txt)
|
|
||||||
# misbehaving apps may include a null byte in the text
|
|
||||||
txt = txt.replace("\x00", "")
|
|
||||||
# reverse the url quoting we added to get images to display
|
|
||||||
txt = self.mw.col.media.escapeImages(txt, unescape=True)
|
|
||||||
self.note.fields[ord] = txt
|
|
||||||
if not self.addMode:
|
|
||||||
self.note.flush()
|
|
||||||
self.mw.requireReset()
|
|
||||||
return ord
|
|
||||||
|
|
||||||
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)):
|
|
||||||
# something updated the note; update it after a subsequent focus
|
|
||||||
# event has had time to fire
|
|
||||||
self.mw.progress.timer(100, self.loadNoteKeepingFocus, False)
|
|
||||||
else:
|
|
||||||
self.checkValid()
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
def mungeHTML(self, txt):
|
def mungeHTML(self, txt):
|
||||||
if txt in ("<br>", "<div><br></div>"):
|
if txt in ("<br>", "<div><br></div>"):
|
||||||
return ""
|
return ""
|
||||||
|
@ -978,9 +970,6 @@ to a cloze type first, via Edit>Change Note Type."""
|
||||||
dupes=showDupes,
|
dupes=showDupes,
|
||||||
paste=onPaste,
|
paste=onPaste,
|
||||||
cutOrCopy=onCutOrCopy,
|
cutOrCopy=onCutOrCopy,
|
||||||
blur=onBlur,
|
|
||||||
focus=onFocus,
|
|
||||||
key=onKey,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue