anki-custom-shortcuts icon indicating copy to clipboard operation
anki-custom-shortcuts copied to clipboard

[Bug] In editor: Shortcuts won't work after clicking outside of the active/focused field

Open kvn1351 opened this issue 2 years ago • 4 comments

Hi, the addon breaks when you click anywhere else than on a field while being in the editor :/ One has to click another field and back to the desired field of choice to reactivate the shortcuts.

Native shortcuts on the other hand, like CMD+B for Bold, continue to work.

I have a hunch that this newly added focusTrap might be causing this (https://github.com/ankitects/anki/pull/1861) but I haven't looked at the code yet.

Also, I've disabled all other addons before testing ofc!

I've made a video to illustrate the issue:

https://user-images.githubusercontent.com/11823348/184041038-bd8ebcdf-bcfa-48dc-900f-5801fe125092.mp4

 

Version Info
macOS Monterey
Version 12.4
Version ⁨2.1.54 (b6a7760c) ⁩
Python 3.9.7 Qt 6.3.1 PyQt 6.3.1

kvn1351 avatar Aug 10 '22 23:08 kvn1351

Hello, Based just on the bug report this one might take a while to figure out, but I am able to fully reproduce what's going on in the video. For the time being, a somewhat ridiculous workaround that I found was to select another field and then select the original field, which restores the shortcut functionality (until clicking away again).

Liresol avatar Aug 11 '22 07:08 Liresol

My initial hunch turned out to be right and I've managed to find a solution.

However, I'm not 100% sure that my fix is without consequences. From my understanding of 8270ce1, there was a slight oversite in regards to the shortcut handling. I've gone into detail about it here: https://github.com/ankitects/anki/pull/1861#issuecomment-1214477083.

    for row in cuts:
        if len(row) == 2:
            keys, fn = row
            #fn = self._addFocusCheck(fn)
        else:
            keys, fn, _ = row
        scut = QShortcut(QKeySequence(keys), self.widget, activated=fn)

You can just comment this out for now in your monkey patch and it should work fine.

kvn1351 avatar Aug 15 '22 00:08 kvn1351

I've noticed this as well, very frustrating.

Apocalypse612 avatar Dec 23 '22 15:12 Apocalypse612

I've noticed this as well, very frustrating.

Idk why he hasn't merged it. But you can just use my fork. It works without any issues.

kvn1351 avatar Dec 23 '22 15:12 kvn1351