anki/qt
Arthur Milchior 0b633dbf40 Ensuring "setNote" is called only once during changing of note type
Initially, I wanted to solve the bug reported on
https://github.com/Arthur-Milchior/anki-html-src-in-field/issues/1

After some research, I finally discovered that the trouble was that,
when we change the note type in add card, the method
`aqt.editor.Editor.loadNote` is called twice. In itself, it would not
be a problem, but given the way callback works, its call back is
called twice on the last version of the webview. Which means that
`gui_hooks.editor_did_load_note` is called twice, which breaks this
add-on.

The reason why loadNote is called twice is because `setNote` is called
twice in `aqt.modelchooser.onModelChange`. The first time through
`gui_hooks.current_note_type_did_change` which calls
`addcards.AddCards.onModelChange` which calls `loadNote`, the second
time through `self.mw.reset()` which calls
`gui_hooks.state_did_reset()` which calls `addcards.AddCards.onReset`
which calls `setAndFocusNote` which calls `setNote`.

I should note furthermore that currently,
`gui_hooks.current_note_type_did_change` is called only when the model
chooser change a model. And `addCards.onModelChange` is never called,
only added to the hook `gui_hooks.current_note_type_did_change`. So
removing the line of code removed in this commit will have no side
effect in Anki itself. It will only affect the fact that this method
is called twice.

I do not know of any add-on calling `onModelChange` or
`gui_hooks.current_note_type_did_change`, but it means little, so of
course, it may always mean an add-on will break because of this
change. No way of being sure.
2020-03-26 21:26:13 +01:00
..
aqt Ensuring "setNote" is called only once during changing of note type 2020-03-26 21:26:13 +01:00
aqt_data/web show spinner when media sync active, click to reveal dialog 2020-02-17 08:40:16 +10:00
designer add switch in prefs for new timezone handling code; bump sync version 2020-03-10 17:50:18 +10:00
ftl Merge branch 'master' into more_precise_config_error_message 2020-03-09 19:41:26 +10:00
po Fixed typecheck-setup.sh: sudo: command not found on Windows 2020-03-17 19:48:16 -03:00
tests FString -> TR 2020-02-27 12:25:19 +10:00
tools Hook editor_note_will_load 2020-03-24 10:17:01 +01:00
ts remove space in fields 2020-03-24 12:26:48 +01:00
.gitignore merge i18n into qt/ 2020-01-03 07:59:00 +10:00
.isort.cfg make sure isort preserves ordering if anki installed into python env 2020-01-03 13:34:51 +10:00
.pylintrc tweaking the folder names again 2020-01-03 07:48:38 +10:00
anki.1 tweaking the folder names again 2020-01-03 07:48:38 +10:00
anki.desktop Add .ankiaddon mime-type on Linux and register Anki as its handler 2020-01-03 17:58:11 +01:00
anki.png tweaking the folder names again 2020-01-03 07:48:38 +10:00
anki.xml Add .ankiaddon mime-type on Linux and register Anki as its handler 2020-01-03 17:58:11 +01:00
anki.xpm tweaking the folder names again 2020-01-03 07:48:38 +10:00
Makefile Fixed moved comment line on qt/aqt/main.py, long variables names on 2020-03-18 11:36:50 -03:00
mypy.ini Fixed mypy and pylint not building on Windows 2020-03-17 19:48:16 -03:00
pkgkey.asc tweaking the folder names again 2020-01-03 07:48:38 +10:00
requirements.dev tweaking the folder names again 2020-01-03 07:48:38 +10:00
requirements.qt tweaking the folder names again 2020-01-03 07:48:38 +10:00
runanki tweaking the folder names again 2020-01-03 07:48:38 +10:00
setup.py use night mode when dark mode active, using standard macOS theme 2020-01-31 13:15:08 +10:00