mirror of
https://github.com/atom/atom.git
synced 2026-01-24 22:38:20 -05:00
Merge pull request #9711 from atom/as-is-text-editor
Export ::isTextEditor function
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 = []
|
||||
|
||||
@@ -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}.
|
||||
|
||||
Reference in New Issue
Block a user