From e919b85fbe68f4b27fc4fbf33c11879fd0ce31b0 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 19 Nov 2015 10:13:58 -0800 Subject: [PATCH 1/6] Export ::isTextEditor function --- exports/atom.coffee | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/exports/atom.coffee b/exports/atom.coffee index c3601e1cc..e28b080f6 100644 --- a/exports/atom.coffee +++ b/exports/atom.coffee @@ -23,10 +23,15 @@ module.exports = unless process.env.ATOM_SHELL_INTERNAL_RUN_AS_NODE module.exports.Task = require '../src/task' + InternalTextEditor = require('../src/text-editor') + + module.exports.isTextEditor = (object) -> + object instanceof InternalTextEditor + TextEditor = (params) -> atom.workspace.buildTextEditor(params) - TextEditor.prototype = require('../src/text-editor').prototype + TextEditor.prototype = InternalTextEditor.prototype Object.defineProperty module.exports, 'TextEditor', enumerable: true From d427091b494be3c5e5fe0f5033c8023bf5bb6b74 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 19 Nov 2015 17:04:18 -0800 Subject: [PATCH 2/6] :white_check_mark: Write specs for ::isTextEditor --- spec/atom-exports-spec.coffee | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 spec/atom-exports-spec.coffee diff --git a/spec/atom-exports-spec.coffee b/spec/atom-exports-spec.coffee new file mode 100644 index 000000000..05752404d --- /dev/null +++ b/spec/atom-exports-spec.coffee @@ -0,0 +1,7 @@ +{isTextEditor} = require 'atom' + +describe "atom exports", -> + describe "::isTextEditor(obj)", -> + it "returns true when the passed object is an instance of `TextEditor`", -> + expect(isTextEditor(atom.workspace.buildTextEditor())).toBe(true) + expect(isTextEditor({getText: ->})).toBe(false) From 2a9cfe6ff148e6cb177934b9fafbe08c3aa80f27 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 19 Nov 2015 17:10:13 -0800 Subject: [PATCH 3/6] :memo: Update deprecation message --- exports/atom.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exports/atom.coffee b/exports/atom.coffee index e28b080f6..952ee0595 100644 --- a/exports/atom.coffee +++ b/exports/atom.coffee @@ -40,7 +40,7 @@ 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 the `isTextEditor` + function in the `atom` exports. (e.g. `{isTextEditor} = require('atom'))` """ TextEditor From 85ee586e2e67a6a661b5b3cb99cb4709106ca6c9 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 19 Nov 2015 17:30:33 -0800 Subject: [PATCH 4/6] :white_check_mark: More specs --- spec/atom-exports-spec.coffee | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/atom-exports-spec.coffee b/spec/atom-exports-spec.coffee index 05752404d..72150b97e 100644 --- a/spec/atom-exports-spec.coffee +++ b/spec/atom-exports-spec.coffee @@ -5,3 +5,5 @@ describe "atom exports", -> it "returns true when the passed object is an instance of `TextEditor`", -> expect(isTextEditor(atom.workspace.buildTextEditor())).toBe(true) expect(isTextEditor({getText: ->})).toBe(false) + expect(isTextEditor(null)).toBe(false) + expect(isTextEditor(undefined)).toBe(false) From 93481c8a0d4c604868715d0572b2b51a614fbacd Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 19 Nov 2015 17:56:53 -0800 Subject: [PATCH 5/6] Move ::isTextEditor down into Workspace --- exports/atom.coffee | 11 +++-------- spec/atom-exports-spec.coffee | 9 --------- spec/workspace-spec.coffee | 7 +++++++ src/workspace.coffee | 6 ++++++ 4 files changed, 16 insertions(+), 17 deletions(-) delete mode 100644 spec/atom-exports-spec.coffee diff --git a/exports/atom.coffee b/exports/atom.coffee index 952ee0595..c3601e1cc 100644 --- a/exports/atom.coffee +++ b/exports/atom.coffee @@ -23,15 +23,10 @@ module.exports = unless process.env.ATOM_SHELL_INTERNAL_RUN_AS_NODE module.exports.Task = require '../src/task' - InternalTextEditor = require('../src/text-editor') - - module.exports.isTextEditor = (object) -> - object instanceof InternalTextEditor - TextEditor = (params) -> atom.workspace.buildTextEditor(params) - TextEditor.prototype = InternalTextEditor.prototype + TextEditor.prototype = require('../src/text-editor').prototype Object.defineProperty module.exports, 'TextEditor', enumerable: true @@ -40,7 +35,7 @@ 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, use the `isTextEditor` - function in the `atom` exports. (e.g. `{isTextEditor} = require('atom'))` + 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`). """ TextEditor diff --git a/spec/atom-exports-spec.coffee b/spec/atom-exports-spec.coffee deleted file mode 100644 index 72150b97e..000000000 --- a/spec/atom-exports-spec.coffee +++ /dev/null @@ -1,9 +0,0 @@ -{isTextEditor} = require 'atom' - -describe "atom exports", -> - describe "::isTextEditor(obj)", -> - it "returns true when the passed object is an instance of `TextEditor`", -> - expect(isTextEditor(atom.workspace.buildTextEditor())).toBe(true) - expect(isTextEditor({getText: ->})).toBe(false) - expect(isTextEditor(null)).toBe(false) - expect(isTextEditor(undefined)).toBe(false) diff --git a/spec/workspace-spec.coffee b/spec/workspace-spec.coffee index 5d7343540..7012d2c4b 100644 --- a/spec/workspace-spec.coffee +++ b/spec/workspace-spec.coffee @@ -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 = [] diff --git a/src/workspace.coffee b/src/workspace.coffee index 396008201..c043c36cf 100644 --- a/src/workspace.coffee +++ b/src/workspace.coffee @@ -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}. From 4abf5922aab9c91098ee6fc874edb117490d3f75 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 19 Nov 2015 17:57:47 -0800 Subject: [PATCH 6/6] :memo: :art: --- exports/atom.coffee | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/exports/atom.coffee b/exports/atom.coffee index c3601e1cc..81d1726b8 100644 --- a/exports/atom.coffee +++ b/exports/atom.coffee @@ -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