From bc56cacd73f9a4a3429120e6cdfeac9747e9df95 Mon Sep 17 00:00:00 2001 From: ijgnd Date: Sat, 22 Apr 2023 11:34:52 +0200 Subject: [PATCH] fix for .50+: #16 --- src/add_hyperlinks.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/add_hyperlinks.py b/src/add_hyperlinks.py index c665289..93ad280 100644 --- a/src/add_hyperlinks.py +++ b/src/add_hyperlinks.py @@ -34,7 +34,7 @@ combine_to_hyperlink, is_valid_url, ) -# from .anki_version_detection import anki_point_version +from .anki_version_detection import anki_point_version from .window import Hyperlink addon_path = os.path.dirname(__file__) @@ -58,8 +58,10 @@ def toggle_hyperlink(editor): # that a user changed. But then I can no longer use document.execCommand('CreateLink' # So I only document.execCommand('CreateLink when the user didn't change the link text # in the dialog. - if selected == h.text: + if selected == h.text and anki_point_version <= 49: js = """ document.execCommand("CreateLink", false, %s); """ % json.dumps(h.url) + elif selected == h.text and anki_point_version >= 50: + js = """ setFormat("CreateLink", %s); """ % json.dumps(h.url) else: js = """ document.execCommand("insertHTML", false, %s); """ % json.dumps(h.replacement) editor.web.eval(js)