Different instances of selection in selectionService.onSelectionChanged

I’m using selectionService.onSelectionChanged to catch selection events from file explorer and from editor tabs.
I noticed that the selection parameter (this.selectionService.selection) in the event handler is different when it’s fired from the file explorer or from editor’s tabs.
When changing the selection from the file explorer i get an array of the selections.
When changing the selection from the editor tabs i get an object of monaco editor with the uri of the selection inside.

Is that inconsistency ok?

[original thread by DoroNahari]

It is expected, different active widgets can have own definition of what is a selection. What are you trying to achieve?

There are helper classes which allow to get different shapes of a selection from SelectionService.

For example UriSelection.getUri, for commands you can simply use UriAwareCommandHandler or WorkspaceRootUriAwareCommandHandler.

for trees there is TreeWidgetSelection

You can also use SelectionCommandHandler to support commands based on your own definition of a selection, see for example FileSelection.CommandHandler


Is there a way to know all of the selection change throwers?

In Theia repo look at who can set SelectionService.selection

I think it is only trees and editors

If you use some custom Theia extension, you will need to check them

just checked, it can be either tree or editor widget