menu
announcement

Spectrum is now read-only. Learn more about the decision in our official announcement.

Theia

Eclipse Theia - Cloud & Desktop IDE

Channels
Team

different instances of selection in selectionService.onSelectionChanged

December 16, 2019 at 2:29pm

different instances of selection in selectionService.onSelectionChanged

December 16, 2019 at 2:29pm
Hi, 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?

December 16, 2019 at 3:03pm
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

December 26, 2019 at 11:11am
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
Edited