superlistapp / super_editor

A Flutter toolkit for building document editors and readers
https://superlist.com/SuperEditor/
MIT License
1.65k stars 239 forks source link

[BUG] - SuperEditor clears selection when application window loses focus #2279

Open miguelcmedeiros opened 2 weeks ago

miguelcmedeiros commented 2 weeks ago

Package Version super_editor main branch (commit https://github.com/superlistapp/super_editor/commit/7eae101b6f1b12956aa1bb348139f50689b61244).

User Info Superlist

To Reproduce Steps to reproduce the behavior:

  1. Go to SuperEditor demo on macOS (or web)
  2. Click on select a word
  3. Move focus to another application (e.g. chrome)
  4. Move focus back to demo app

Actual behavior Selection is cleared.

Expected behavior Selection should be the same as before switching to another application.

Platform macOS and web.

Flutter version master

Screenshots

https://github.com/user-attachments/assets/900f7d87-0398-4ba7-aa44-bda84de84d46

miguelcmedeiros commented 2 weeks ago

Cc @matthew-carroll @angelosilvestre

knopp commented 2 weeks ago

Possibly seems like app lifecycle event being reported wrong on macOS. Looking into it.

knopp commented 2 weeks ago

Nevermind, that was a red herring. Super_editor unfocuses on IME disconnected, but it only refocuses (and thus restores selection) when being interacted or scrolling. So this seems like super_editor issue?

matthew-carroll commented 2 weeks ago

@knopp is there a way to identify the situation where the window loses focus and regains it? In the case where the IME connection closes but the focus remains in the current window, I think we probably have the desired behavior. I think it's only when switching between windows that we're seeing an undesirable policy. But I'm not sure where to detect that situation.

Also @miguelcmedeiros experimented with a standard Flutter text field and it appears that in some manner it retains focus between window focus changes. Miguel found that when typing in a regular Flutter text field, it seems to retain caret position when regaining window focus, and also allows for immediate typing through the IME connection.

SuperTextField somehow has a middle ground. When the Flutter window regains focus the SuperTextField regains a selection, but the selection places the caret at the end of the content. Despite the caret, you can't type into the SuperTextField until the user taps on it (probably to give it focus).

We should create a consistent result for window focus change.

matthew-carroll commented 2 weeks ago

CC @angelosilvestre