The selection highlight of text disappears when Anki loses focus

This is a bug report

Steps to reproduce:

  1. Run Anki-24.04.1 on X11 Linux.
  2. Open the card browser and select some text in a field.
  3. The selected text gets a blue selection highlight.
  4. Focus on another window, causing the browser window to lose focus.
  5. The blue selection highlight now disappears and you can’t tell what is selected.

The text remains selected and the highlight returns when focus is restored.

This is annoying since I often accidentally try to select a field without realizing it’s already selected, which triggers a drag-and-drop animation of the text instead of a selection.

1 Like

I found another way to trigger what I believe is the same bug, so I’ll document that as well.

New steps to reproduce:

  1. Open the deck browser and pick a card.
  2. Select some text in a field.
  3. Pick a different card in the browser without selecting any fields on the new card.
  4. Go back to the original card again.
  5. The text you previously selected has lost the blue selection highlight and is no longer visibly selected.
  6. Surprise! The text is actually still selected, but with an invisible selection highlight. Trying to select the same text again results in a drag-and-drop animation.

It’s the same problem with missing selection highlight on selected text. Switching cards in the browser causes the same behavior as when the browser window loses focus.

Just chiming in to say this isn’t Linux-specific. Both cases are reproducible for me on Windows 11. I’m on a slightly older version, but it’s been like this for a while, and I don’t see any recent updates that address it.

Version ⁨23.12.1 (1a1d4d54)⁩
Python 3.9.15 Qt 6.6.1 PyQt 6.6.1

Since this appears to be limited to the editing screen, it seems to imply it’s something we may have control over. I’m not sure what’s causing it though - perhaps it’s related to the shadow root that each field in the editor uses.

1 Like

I tried to set the QTWEBENGINE_REMOTE_DEBUGGING=8080 environment variable and experimented with the debugger. The “anki-editable” textbox had several event listeners. I removed each one in turn to see if that changed anything. If I remove either the “blur” or “focus” event listeners, the bug disappears. There seems to be some kind of callback in the code listening for (un)focus events that removes the blue selection highlight. According to the debugger the problematic event listeners are defined at “anki-editable.svelte-18uwveo editor.js:587”.

I know next to nothing about Svelte or JavaScript in general, so I’m not sure how useful this information is.


Thanks for the extra digging. I’ve logged this on The selection highlight of text disappears when Anki loses focus · Issue #3251 · ankitects/anki · GitHub so it doesn’t get forgotten about.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.