From cf50625cc6673313952c12ec7b24f78974e10ffe Mon Sep 17 00:00:00 2001 From: Jason Rudolph Date: Wed, 31 May 2017 14:32:20 -0400 Subject: [PATCH] Teach Workspace::getActiveTextEditor() to get item from center --- spec/workspace-spec.js | 36 ++++++++++++++++++++++++++++++++++++ src/workspace.js | 8 ++++---- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/spec/workspace-spec.js b/spec/workspace-spec.js index 9eaa17bcd..98b448c2b 100644 --- a/spec/workspace-spec.js +++ b/spec/workspace-spec.js @@ -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 = [] diff --git a/src/workspace.js b/src/workspace.js index 414065203..08f0c5c7b 100644 --- a/src/workspace.js +++ b/src/workspace.js @@ -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 } }