add app.activeWindowChanged, Window.activeEditorChanged, codeEditor.selectionChanged
Created by: lguychard
- Fixes #2026 (closed)
- Prerequisite to merging sourcegraph/sourcegraph-git-extras#14
This pull request adds the following to the Sourcegraph extension API:
sourcegraph.app.activeWindowChanged
Window.activeEditorChanged
codeEditor.selectionChanged
These events are backed by rxjs observables, and can be composed as such (also exemplified in tests):
const selectionChanges = from(extensionHost.app.activeWindowChanged).pipe(
filter((window): window is Window => window !== undefined),
switchMap(window => window.activeViewComponentChanged),
filter((editor): editor is CodeEditor => editor !== undefined),
switchMap(editor => editor.selectionsChanged)
)
In the current implementation, all instances of ExtWindow
and ExtCodeEditor
exposed to extensions are recreated every time model
emits. As a result, activeViewComponentChanged
and selectionsChanged
are declared using of()
, since they will only ever have one value. This is likely to change in the future, but will not require changing the extension API.
As part of this PR, I made sure that the Subscribable.subscribe()
overloads we declare in sourcegraph.d.ts
were compatible with the latest RX version, 6.4.0, so that the new events could be used as ObservableInput
.