Add Workspace::observeActiveTextEditor()

This commit is contained in:
Jason Rudolph
2017-05-31 16:08:24 -04:00
parent cf50625cc6
commit 05efc143ed
2 changed files with 107 additions and 0 deletions

View File

@@ -216,6 +216,7 @@ module.exports = class Workspace extends Model {
bottom: this.createDock('bottom')
}
this.activePaneContainer = this.paneContainers.center
this.activeTextEditor = null
this.panelContainers = {
top: new PanelContainer({viewRegistry: this.viewRegistry, location: 'top'}),
@@ -422,6 +423,17 @@ module.exports = class Workspace extends Model {
this.didChangeActivePaneItem(item)
this.emitter.emit('did-change-active-pane-item', item)
}
if (paneContainer === this.getCenter()) {
const activeTextEditorChanged =
(item instanceof TextEditor) || (this.activeTextEditor instanceof TextEditor)
if (activeTextEditorChanged) {
this.activeTextEditor = (item instanceof TextEditor) ? item : null
const itemValue = (item instanceof TextEditor) ? item : undefined
this.emitter.emit('did-change-active-text-editor', itemValue)
}
}
}
didChangeActivePaneItem (item) {
@@ -648,6 +660,10 @@ module.exports = class Workspace extends Model {
return this.emitter.on('did-stop-changing-active-pane-item', callback)
}
onDidChangeActiveTextEditor (callback) {
return this.emitter.on('did-change-active-text-editor', callback)
}
// Essential: Invoke the given callback with the current active pane item and
// with all future active pane items in the workspace.
//
@@ -660,6 +676,13 @@ module.exports = class Workspace extends Model {
return this.onDidChangeActivePaneItem(callback)
}
observeActiveTextEditor (callback) {
const activeTextEditor = this.getActiveTextEditor()
if (activeTextEditor != null) { callback(activeTextEditor) }
return this.onDidChangeActiveTextEditor(callback)
}
// Essential: Invoke the given callback whenever an item is opened. Unlike
// {::onDidAddPaneItem}, observers will be notified for items that are already
// present in the workspace when they are reopened.