Merge pull request #9711 from atom/as-is-text-editor

Export ::isTextEditor function
This commit is contained in:
Antonio Scandurra
2015-11-20 08:42:28 -08:00
3 changed files with 14 additions and 2 deletions

View File

@@ -35,7 +35,6 @@ unless process.env.ATOM_SHELL_INTERNAL_RUN_AS_NODE
The `TextEditor` constructor is no longer public.
To construct a text editor, use `atom.workspace.buildTextEditor()`.
To check if an object is a text editor, look for for the existence of
a public method that you're using (e.g. `::getText`).
To check if an object is a text editor, use `atom.workspace.isTextEditor(object)`.
"""
TextEditor

View File

@@ -658,6 +658,13 @@ describe "Workspace", ->
waitsForPromise -> workspace.openLicense()
runs -> expect(workspace.getActivePaneItem().getText()).toMatch /Copyright/
describe "::isTextEditor(obj)", ->
it "returns true when the passed object is an instance of `TextEditor`", ->
expect(workspace.isTextEditor(atom.workspace.buildTextEditor())).toBe(true)
expect(workspace.isTextEditor({getText: ->})).toBe(false)
expect(workspace.isTextEditor(null)).toBe(false)
expect(workspace.isTextEditor(undefined)).toBe(false)
describe "::observeTextEditors()", ->
it "invokes the observer with current and future text editors", ->
observed = []

View File

@@ -518,6 +518,12 @@ class Workspace extends Model
@project.bufferForPath(filePath, options).then (buffer) =>
@buildTextEditor(_.extend({buffer, largeFileMode}, options))
# Public: Returns a {Boolean} that is `true` if `object` is a `TextEditor`.
#
# * `object` An {Object} you want to perform the check against.
isTextEditor: (object) ->
object instanceof TextEditor
# Extended: Create a new text editor.
#
# Returns a {TextEditor}.