Teach Workspace::getActiveTextEditor() to get item from center

This commit is contained in:
Jason Rudolph 2017-05-31 14:32:20 -04:00
parent 61a52d49aa
commit cf50625cc6
No known key found for this signature in database
GPG Key ID: B760F197E561DF15
2 changed files with 40 additions and 4 deletions

View File

@ -1419,6 +1419,42 @@ describe('Workspace', () => {
})
})
describe('::getActiveTextEditor()', () => {
describe("when the workspace center's active pane item is a text editor", () => {
describe('when the workspace center has focus', function () {
it('returns the text editor', () => {
const workspaceCenter = workspace.getCenter()
const editor = new TextEditor()
workspaceCenter.getActivePane().activateItem(editor)
workspaceCenter.activate()
expect(workspace.getActiveTextEditor()).toBe(editor)
})
})
describe('when a dock has focus', function () {
it('returns the text editor', () => {
const workspaceCenter = workspace.getCenter()
const editor = new TextEditor()
workspaceCenter.getActivePane().activateItem(editor)
workspace.getLeftDock().activate()
expect(workspace.getActiveTextEditor()).toBe(editor)
})
})
})
describe("when the workspace center's active pane item is not a text editor", () => {
it('returns undefined', () => {
const workspaceCenter = workspace.getCenter()
const nonEditorItem = document.createElement('div')
workspaceCenter.getActivePane().activateItem(nonEditorItem)
expect(workspace.getActiveTextEditor()).toBeUndefined()
})
})
})
describe('::observeTextEditors()', () => {
it('invokes the observer with current and future text editors', () => {
const observed = []

View File

@ -1282,12 +1282,12 @@ module.exports = class Workspace extends Model {
return this.getPaneItems().filter(item => item instanceof TextEditor)
}
// Essential: Get the active item if it is an {TextEditor}.
// Essential: Get the workspace center's active item if it is a {TextEditor}.
//
// Returns an {TextEditor} or `undefined` if the current active item is not an
// {TextEditor}.
// Returns a {TextEditor} or `undefined` if the workspace center's current
// active item is not a {TextEditor}.
getActiveTextEditor () {
const activeItem = this.getActivePaneItem()
const activeItem = this.getCenter().getActivePaneItem()
if (activeItem instanceof TextEditor) { return activeItem }
}