JetBrains / jewel

An implementation of the IntelliJ look and feels in Compose for Desktop
Apache License 2.0
636 stars 30 forks source link

Improve selection behaviours on SLC #373

Open fscarponi opened 2 months ago

fscarponi commented 2 months ago

Screen recording of Swing list behaviour

So, I checked and the Swing behaviour is as follows:

  1. [Solved] When focusing a list, either the previous selection is kept, or the first item gets selected (if there is any item in the list)
  2. When the current selection is gone (e.g., item removed), the item above (i.e., selectedIndex - 1) is selected
  3. If the item was the first one, then the next one is selected (i.e., the selection remains on selectedIndex even if the item is now different)
  4. If there are no items left, the selection is null
  5. The selection can only be null when the list is empty, or if it has never received focus before

On multi-select lists, it pretty much follows the same rules. The only difference is that when there are multiple items selected and one of them disappears, the item also disappears from the selection, but other selected items remain selected. If all selected items are removed, the behaviour is the same as for the single-select list.

We should align to this behaviour. If the list is empty when it receives focus, it'll have no selection, but as soon as the user uses the keyboard to move the selection, a selection is created on the first item. If apps want to create a selection once they add data to the list, they're free to do so, but we won't do it for them.

Originally posted by @rock3r in https://github.com/JetBrains/jewel/issues/357#issuecomment-2068988619