Deprecate Dock::getActiveTextEditor()

This commit is contained in:
Jason Rudolph
2017-06-01 15:24:50 -04:00
parent e569f8fc4d
commit f8ebd71200
2 changed files with 15 additions and 1 deletions

View File

@@ -1,5 +1,7 @@
/** @babel */
const Grim = require('grim')
import {it, fit, ffit, fffit, beforeEach, afterEach} from './async-spec-helpers'
describe('Dock', () => {
@@ -329,4 +331,13 @@ describe('Dock', () => {
expect(() => atom.workspace.getElement().handleDragStart(dragEvent)).not.toThrow()
})
})
describe('::getActiveTextEditor()', () => {
it('is deprecated', () => {
spyOn(Grim, 'deprecate')
atom.workspace.getLeftDock().getActiveTextEditor()
expect(Grim.deprecate.callCount).toBe(1)
})
})
})

View File

@@ -4,6 +4,7 @@ const _ = require('underscore-plus')
const {CompositeDisposable} = require('event-kit')
const PaneContainer = require('./pane-container')
const TextEditor = require('./text-editor')
const Grim = require('grim')
const MINIMUM_SIZE = 100
const DEFAULT_INITIAL_SIZE = 300
@@ -590,11 +591,13 @@ module.exports = class Dock {
return this.paneContainer.getTextEditors()
}
// Essential: Get the active item if it is a {TextEditor}.
// Deprecated: Get the active item if it is a {TextEditor}.
//
// Returns a {TextEditor} or `undefined` if the current active item is not a
// {TextEditor}.
getActiveTextEditor () {
Grim.deprecate('Text editors are not allowed in docks. Use atom.workspace.getActiveTextEditor() instead.')
const activeItem = this.getActivePaneItem()
if (activeItem instanceof TextEditor) { return activeItem }
}