Make sure editor note is saved before triggering buttons (#2995)

This commit is contained in:
Abdo 2024-02-11 09:07:49 +03:00 committed by GitHub
parent db02c95eb5
commit 5f9e07ea7a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -4,6 +4,7 @@
from __future__ import annotations from __future__ import annotations
import base64 import base64
import functools
import html import html
import itertools import itertools
import json import json
@ -238,12 +239,18 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too
) -> str: ) -> str:
"""Assign func to bridge cmd, register shortcut, return button""" """Assign func to bridge cmd, register shortcut, return button"""
if func: if func:
self._links[cmd] = func
def wrapped_func(editor: Editor) -> None:
self.call_after_note_saved(
functools.partial(func, editor), keepFocus=True
)
self._links[cmd] = wrapped_func
if keys: if keys:
def on_activated() -> None: def on_activated() -> None:
func(self) wrapped_func(self)
if toggleable: if toggleable:
# generate a random id for triggering toggle # generate a random id for triggering toggle