From 90c326b985c7c2e255472114439872f00f44432b Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Fri, 17 Mar 2017 17:17:18 -0600 Subject: [PATCH] Fix clearing of marker-specific properties for layer decorations --- spec/text-editor-component-spec.js | 24 ++++++++++++++++++++++++ src/decoration-manager.js | 3 ++- src/layer-decoration.coffee | 3 ++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/spec/text-editor-component-spec.js b/spec/text-editor-component-spec.js index 8cab5b645..9967901ce 100644 --- a/spec/text-editor-component-spec.js +++ b/spec/text-editor-component-spec.js @@ -784,6 +784,30 @@ describe('TextEditorComponent', () => { !highlights[1].classList.contains('e') ) }) + + it('supports layer decorations', async () => { + const {component, element, editor} = buildComponent({rowsPerTile: 12}) + const markerLayer = editor.addMarkerLayer() + const marker1 = markerLayer.markScreenRange([[2, 4], [3, 4]]) + const marker2 = markerLayer.markScreenRange([[5, 6], [7, 8]]) + const decoration = editor.decorateMarkerLayer(markerLayer, {type: 'highlight', class: 'a'}) + await component.getNextUpdatePromise() + + const highlights = element.querySelectorAll('.highlight') + expect(highlights[0].classList.contains('a')).toBe(true) + expect(highlights[1].classList.contains('a')).toBe(true) + + decoration.setPropertiesForMarker(marker1, {type: 'highlight', class: 'b'}) + await component.getNextUpdatePromise() + expect(highlights[0].classList.contains('b')).toBe(true) + expect(highlights[1].classList.contains('a')).toBe(true) + + decoration.setPropertiesForMarker(marker1, null) + decoration.setPropertiesForMarker(marker2, {type: 'highlight', class: 'c'}) + await component.getNextUpdatePromise() + expect(highlights[0].classList.contains('a')).toBe(true) + expect(highlights[1].classList.contains('c')).toBe(true) + }) }) describe('mouse input', () => { diff --git a/src/decoration-manager.js b/src/decoration-manager.js index 84278eb8f..ec8b8b684 100644 --- a/src/decoration-manager.js +++ b/src/decoration-manager.js @@ -100,7 +100,8 @@ class DecorationManager { if (layerDecorations) { layerDecorations.forEach((layerDecoration) => { - decorationPropertiesForMarker.push(layerDecoration.getPropertiesForMarker(marker) || layerDecoration.getProperties()) + const properties = layerDecoration.getPropertiesForMarker(marker) || layerDecoration.getProperties() + decorationPropertiesForMarker.push(properties) }) } diff --git a/src/layer-decoration.coffee b/src/layer-decoration.coffee index 03be59b14..e20921b4d 100644 --- a/src/layer-decoration.coffee +++ b/src/layer-decoration.coffee @@ -53,10 +53,11 @@ class LayerDecoration setPropertiesForMarker: (marker, properties) -> return if @destroyed @overridePropertiesByMarker ?= new Map() + marker = @markerLayer.getMarker(marker.id) if properties? @overridePropertiesByMarker.set(marker, properties) else - @overridePropertiesByMarker.delete(marker.id) + @overridePropertiesByMarker.delete(marker) @decorationManager.emitDidUpdateDecorations() getPropertiesForMarker: (marker) ->