The underlying service is broken.
with (say) 10 layers, click to select one - and all is fine.
Ctrl-click to add to the selection lower down the list - that one gets the highlight, and is returned as the "working" one.
Ctrl-click to add to the selection higher up the list - that one gets the highlight, but the lower one is still the one that is returned as "working".
similarly with click, then shift-click to extend the range -- shift-click higher: still the lowest returned; shift-click lower: "all is well".
Which suggests to me that the layer with the lowest AbsoluteId is always returned as active from doc:GetSelectedLayer(0)
(even though the correct layer is active in the work area)
===
Ramón López wrote: ↑Wed Feb 22, 2023 6:34 am

And talking about that... Do you thing something like can do "doc:GetSelectedLayer(-1)" (yeah, I tried it!) for getting the working layer could be like a good proposal for a feature request? ....
FWIW I tried doc:GetSelectedLayer() (i.e. a nil) and that worked exactly as a doc:GetSelectedLayer(0) -- which tells me that we "almost" have the suggested feature - but the service would still need to be fixed for it to work