mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Add Workspace::observeActiveTextEditor()
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user