From 5e766b6eee31c9d4abb2235f98c9a6395822d5ed Mon Sep 17 00:00:00 2001 From: Jess Lin Date: Wed, 29 Apr 2015 08:53:04 -0700 Subject: [PATCH] [Gutter] Clear custom gutter decorations from previous usages of a custom gutter element --- spec/text-editor-element-spec.coffee | 15 +++++++++++++++ src/custom-gutter-component.coffee | 2 ++ 2 files changed, 17 insertions(+) diff --git a/spec/text-editor-element-spec.coffee b/spec/text-editor-element-spec.coffee index 418e0367d..435b3a4a5 100644 --- a/spec/text-editor-element-spec.coffee +++ b/spec/text-editor-element-spec.coffee @@ -79,6 +79,21 @@ describe "TextEditorElement", -> jasmine.attachToDOM(element) expect(element.shadowRoot.querySelectorAll('.line-number').length).toBe initialCount + it "does not render duplicate decorations in custom gutters", -> + editor = new TextEditor + editor.setText('1\n2\n3') + editor.addGutter({name: 'test-gutter'}) + marker = editor.markBufferRange([[0,0],[2,0]]) + editor.decorateMarker(marker, {type: 'gutter', gutterName: 'test-gutter'}) + element = atom.views.getView(editor) + + jasmine.attachToDOM(element) + initialDecorationCount = element.shadowRoot.querySelectorAll('.decoration').length + + element.remove() + jasmine.attachToDOM(element) + expect(element.shadowRoot.querySelectorAll('.decoration').length).toBe initialDecorationCount + describe "focus and blur handling", -> describe "when the editor.useShadowDOM config option is true", -> it "proxies focus/blur events to/from the hidden input inside the shadow root", -> diff --git a/src/custom-gutter-component.coffee b/src/custom-gutter-component.coffee index 380322e8b..1321c8990 100644 --- a/src/custom-gutter-component.coffee +++ b/src/custom-gutter-component.coffee @@ -13,6 +13,8 @@ class CustomGutterComponent @domNode = atom.views.getView(@gutter) @decorationsNode = @domNode.firstChild + # Clear the contents in case the domNode is being reused. + @decorationsNode.innerHTML = '' getDomNode: -> @domNode