Editor focus handling in 2.1.53+

Hi,
a user of an add-on just reported an issue in 2.1.53 to me, and I just tested and can confirm it.
The add-on in case inserts additional UI elements in the Add window. Some of the add-on’s functionality depends on being able to select text in that inserted UI.

However, 2.1.53 seems to not allow to select anything outside the fields text boxes. As soon as I focus one of the fields, I cannot select anything outside anymore (I can actually perform the select operation, i.e. dragging over some text, but on mouse release, nothing happens).
I’m having a hard time understanding the new editor field components, maybe someone could point me into the direction of what changes in 2.1.53 caused this change in behaviour? I can confirm it was still working in 2.1.52.

Add-on in case, e.g. you cannot select text in the PDF anymore in 2.1.53.

1 Like

Can you bisect the changes to figure out which commit broke your use case?

My guess would be #1861

2 Likes

That seems definitely like it.
Is that intended behaviour as it is working right now? As far as I understand it, on the blur event, the component checks which element was clicked(?), and if it is another input, it receives focus, otherwise, the element focuses itself again?

Have you been able to find a workaround @prollo? If this is something that can’t be fixed without changes to Anki, maybe we could look into a flag the add-on can set to disable this functionality or similar.

A friendly person on Github found a workaround:

let siacView = document.getElementById('siac-right-side');

siacView.addEventListener('mousedown', function() {
    // one solution would be to have a hidden field for this sole purpose
    let someNonAnkiField = document.getElementById('siac-pdf-page-inp');
    someNonAnkiField.focus();
    someNonAnkiField.blur();
}, false);

It works, but feels kinda hack-ish.

2 Likes

@hengiesel is there some easy change we could make to improve the situation, or do we need to start recommending this approach going forward?