Yes,. i already noticed that too. Previously (i assumed a special keyboard navigation routine would be needed to be written attached to the keypress (*)), and now again actually, as you told the your selection jumped to the top of the list.
My interpretation had been: ok. one thinks he's still in the editor, but in fact the editor already did close underneath, and so the key did apply to the listview, not the editor.
(*) Checked against my old app (Delphi 7) how that did behave (without special coding): typing a character, it did stay on the currently selected item. If none selected, it does nothing. I'd doubt that there is a builtin mechanism here
About "Selected" within "Edited" i've no clear picture yet, but i did wonder a bit why (in your demo) OnSelectItem had been called twice, the first with Selected nil resp. itemindex -1.
(that's probably just the nm^.iItem = -1 see below). No real opinion yet.
Meanwhile .. the matter didn't let me rest... I took a closer look at the "end editing" process and values and maybe there is a less aggressive / more specific solution that does cover the logics discussed.
If you should have the time to after Easter, could you give it a short look and try?
// Does relate to:
https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/39708 // end editing
if IsEditing then
if (nm^.iItem = -1) And (FSelectedIdx<>-1) then // specifically when item outside the editor clicked
if Not ((FFocused <> nil) And FFocused.Selected) then // but prevent known side effect (defocusing at repeated /click/edit with Click on the same item)
HideEditor;
I did already test, with special regard to the side effect, with the application some time and it did meet the expectation.
I think it’s at least much more better than before
If you find it promising and worthy, I would subject it to a more extensive test here.
Generally, i did struggle with the virtual listview since a longer time, as you probably remember, but meanwhile i felt that the main hurdles had been resolved. There are more use cases and so more hurdles though.