I am guessing:
- Anchordocking?
- one source editor docked to the main window (one window that has main menu and editor)?
- 2nd source editor floating?
Are you using a keycombo to activate the sort? (NOT a keycombo to activate the main menu)
Or a you using the main menu?
Because, if you use the main menu, then you activate that window, and I would expect that moves focus to that window...
If that is the case, then I don't know. One could call it a design flaw, or a bug, or expected behaviour.
If that is Windows (and I guess other OS will have similar), then Windows sends the WM_ACTIVATE message. When a window is activated, it focuses the previously focused focusable-widget it has.
Then I wrote all this, and though I try. And I can select "sort selection" and it always applies to the editor last focused before I click the main menu.
Though that is Windows 10. Maybe Windows 11 differs...
And it is Lazarus 4.1 (the fixes branch). Not sure, have to check if it got any relevant fixes...
But then, I started with a big guess. Maybe your setup is different from that?