anki/qt/aqt
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
..
__init__.py drop the separate i18n backend 2020-03-20 21:15:23 +10:00
.gitignore basic night mode support 2020-01-23 17:27:07 +10:00
about.py add Tobias to contributors 2020-02-24 18:36:37 +10:00
addcards.py Ensuring "setNote" is called only once during changing of note type 2020-03-26 21:26:13 +01:00
addons.py Allow add-on dev to show personalized message. 2020-03-11 01:39:39 +01:00
browser.py Change not not to bool 2020-03-23 11:16:39 -06:00
clayout.py hook for initializing clayout 2020-03-01 11:42:41 +01:00
customstudy.py radioCram 2020-02-03 02:24:37 -08:00
deckbrowser.py imports 2020-03-14 22:10:27 +10:00
deckchooser.py correct missing french translation 2020-02-05 20:48:30 -08:00
deckconf.py Use a consistent function signature across load and save hooks 2020-02-24 15:47:48 +01:00
dyndeckconf.py tweaking the folder names again 2020-01-03 07:48:38 +10:00
editcurrent.py add qconnect helper and some type hints 2020-01-16 07:41:23 +10:00
editor.py Merge pull request #523 from Arthur-Milchior/hook_note_will_load 2020-03-25 09:43:16 +10:00
errors.py restore mpv/mplayer missing warning that got lost in the av changes 2020-02-29 21:20:08 +10:00
exporting.py export in a background thread 2020-03-20 21:15:23 +10:00
fields.py tweaking the folder names again 2020-01-03 07:48:38 +10:00
gui_hooks.py Hook editor_note_will_load 2020-03-24 10:17:01 +01:00
importing.py import .colpkg in a background thread 2020-03-20 21:15:23 +10:00
legacy.py add missing short argument to legacy fmtTimeSpan() 2020-02-26 20:36:59 +10:00
main.py Merge remote-tracking branch 'danielelmes/master' into fix_tests_on_windows 2020-03-23 18:44:11 -03:00
mediacheck.py add Collection struct, and get media check working again 2020-03-20 21:15:23 +10:00
mediasrv.py match both forward slash and os seperator 2020-02-29 12:36:10 +09:00
mediasync.py formatting 2020-03-23 19:54:01 +10:00
modelchooser.py correct missing french translation 2020-02-05 20:48:30 -08:00
models.py Hook models_advanced_will_show 2020-03-19 12:03:09 +01:00
mpv.py formatting fixes 2020-01-21 20:39:25 +10:00
overview.py fix typo 2020-02-19 17:46:12 +09:00
pinnedmodules.py pin fcntl, which went missing on Linux in a recent update 2020-02-19 19:59:31 +10:00
preferences.py fix English being shown in prefs for fully qualified langs like zh-CN 2020-03-23 16:08:06 +10:00
profiles.py migrate strings with trailing newlines to fluent 2020-02-27 20:36:40 +10:00
progress.py fix mypy warning 2020-03-20 21:15:23 +10:00
py.typed mark anki and aqt modules as having typing info 2020-01-13 13:03:37 +10:00
qt.py fix cases where we used the wrong type sig to connect to gui hook 2020-01-16 07:53:12 +10:00
reviewer.py Give the 'typearrow' id to the type answer arrow 2020-03-16 00:42:08 -03:00
sound.py reduce the chances of a race condition in mplayer code 2020-03-23 19:15:32 +10:00
stats.py Assume that web assets without a specified subpath are under /_anki 2020-02-15 15:03:43 +01:00
studydeck.py forceDefault to force_default 2020-02-22 04:01:42 -08:00
sync.py drop log= argument from Collection 2020-03-20 21:15:23 +10:00
tagedit.py tweaking the folder names again 2020-01-03 07:48:38 +10:00
taglimit.py tweaking the folder names again 2020-01-03 07:48:38 +10:00
taskman.py Apply mypy improvements to aqt 2020-02-26 22:27:58 -05:00
theme.py cache dark mode value so UI doesn't break when it changes 2020-03-23 18:39:37 +10:00
toolbar.py Monkeytype qt/aqt/toolbar.py 2020-03-01 10:16:08 -05:00
tts.py fix audio getting stuck (2/2) 2020-03-15 09:34:04 +10:00
update.py tweaking the folder names again 2020-01-03 07:48:38 +10:00
utils.py FString -> TR 2020-02-27 12:25:19 +10:00
webview.py Monkeytype qt/aqt/webview.py 2020-03-01 10:16:08 -05:00
winpaths.py tweaking the folder names again 2020-01-03 07:48:38 +10:00