So, I checked and the Swing behaviour is as follows:
[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)
When the current selection is gone (e.g., item removed), the item above (i.e., selectedIndex - 1) is selected
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)
If there are no items left, the selection is null
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.
So, I checked and the Swing behaviour is as follows:
selectedIndex - 1
) is selectedselectedIndex
even if the item is now different)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