From 5c37d208f5d1feddc8bd3e2b2eb3b4875df59d0c Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 8 Dec 2014 16:56:46 -0800 Subject: [PATCH] Don't throw when ::getDefaultCharacterWidth is called while detached --- spec/text-editor-element-spec.coffee | 4 ++-- src/text-editor-element.coffee | 3 --- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/spec/text-editor-element-spec.coffee b/spec/text-editor-element-spec.coffee index 205cc9910..b5f05f4d9 100644 --- a/spec/text-editor-element-spec.coffee +++ b/spec/text-editor-element-spec.coffee @@ -147,9 +147,9 @@ describe "TextEditorElement", -> expect(element.shadowRoot.textContent).toContain "goodbye" describe "::getDefaultCharacterWidth", -> - it "throws an exception if the editor is not attached", -> + it "returns null before the element is attached", -> element = new TextEditorElement - expect(-> element.getDefaultCharacterWidth()).toThrow("The editor must be attached to get the default character width") + expect(element.getDefaultCharacterWidth()).toBeNull() it "returns the width of a character in the root scope", -> element = new TextEditorElement diff --git a/src/text-editor-element.coffee b/src/text-editor-element.coffee index 426e450ef..47fc3f67a 100644 --- a/src/text-editor-element.coffee +++ b/src/text-editor-element.coffee @@ -60,7 +60,6 @@ class TextEditorElement extends HTMLElement @__spacePenView = new TextEditorView(this) attachedCallback: -> - @attached = true @buildModel() unless @getModel()? @mountComponent() unless @component?.isMounted() @component.checkForVisibilityChange() @@ -68,7 +67,6 @@ class TextEditorElement extends HTMLElement @emitter.emit("did-attach") detachedCallback: -> - @attached = false @emitter.emit("did-detach") initialize: (model) -> @@ -173,7 +171,6 @@ class TextEditorElement extends HTMLElement # # Returns a {Number} of pixels. getDefaultCharacterWidth: -> - throw new Error("The editor must be attached to get the default character width") unless @attached @getModel().getDefaultCharWidth() # Extended: call the given `callback` when the editor is attached to the DOM.