From 28508d9a3f0e27969c177f6cf0ea9843fc3dd560 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 14 Feb 2017 11:30:13 -0700 Subject: [PATCH] Make decorationsForScreenRowRange return all decorations Even if they are for markers that aren't on the default marker layer --- spec/decoration-manager-spec.coffee | 19 ++++++++++++++----- spec/text-editor-component-spec.js | 7 +++++-- src/decoration-manager.coffee | 8 +++++--- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/spec/decoration-manager-spec.coffee b/spec/decoration-manager-spec.coffee index 908f78f36..53854659d 100644 --- a/spec/decoration-manager-spec.coffee +++ b/spec/decoration-manager-spec.coffee @@ -1,12 +1,13 @@ DecorationManager = require '../src/decoration-manager' describe "DecorationManager", -> - [decorationManager, buffer, defaultMarkerLayer, displayLayer] = [] + [decorationManager, buffer, defaultMarkerLayer, displayLayer, otherMarkerLayer] = [] beforeEach -> buffer = atom.project.bufferForPathSync('sample.js') displayLayer = buffer.addDisplayLayer() defaultMarkerLayer = displayLayer.addMarkerLayer() + otherMarkerLayer = displayLayer.addMarkerLayer() decorationManager = new DecorationManager(displayLayer, defaultMarkerLayer) waitsForPromise -> @@ -17,21 +18,29 @@ describe "DecorationManager", -> buffer.release() describe "decorations", -> - [marker, decoration, decorationProperties] = [] + [marker, layerMarker, decoration, layerMarkerDecoration, decorationProperties] = [] beforeEach -> marker = defaultMarkerLayer.markBufferRange([[2, 13], [3, 15]]) decorationProperties = {type: 'line-number', class: 'one'} decoration = decorationManager.decorateMarker(marker, decorationProperties) + layerMarker = otherMarkerLayer.markBufferRange([[2, 13], [3, 15]]) + layerMarkerDecoration = decorationManager.decorateMarker(layerMarker, decorationProperties) it "can add decorations associated with markers and remove them", -> expect(decoration).toBeDefined() expect(decoration.getProperties()).toBe decorationProperties expect(decorationManager.decorationForId(decoration.id)).toBe decoration - expect(decorationManager.decorationsForScreenRowRange(2, 3)[marker.id][0]).toBe decoration + expect(decorationManager.decorationsForScreenRowRange(2, 3)).toEqual { + "#{marker.id}": [decoration], + "#{layerMarker.id}": [layerMarkerDecoration] + } decoration.destroy() expect(decorationManager.decorationsForScreenRowRange(2, 3)[marker.id]).not.toBeDefined() expect(decorationManager.decorationForId(decoration.id)).not.toBeDefined() + layerMarkerDecoration.destroy() + expect(decorationManager.decorationsForScreenRowRange(2, 3)[layerMarker.id]).not.toBeDefined() + expect(decorationManager.decorationForId(layerMarkerDecoration.id)).not.toBeDefined() it "will not fail if the decoration is removed twice", -> decoration.destroy() @@ -63,9 +72,9 @@ describe "DecorationManager", -> describe "::getDecorations(properties)", -> it "returns decorations matching the given optional properties", -> - expect(decorationManager.getDecorations()).toEqual [decoration] + expect(decorationManager.getDecorations()).toEqual [decoration, layerMarkerDecoration] expect(decorationManager.getDecorations(class: 'two').length).toEqual 0 - expect(decorationManager.getDecorations(class: 'one').length).toEqual 1 + expect(decorationManager.getDecorations(class: 'one').length).toEqual 2 describe "::decorateMarker", -> describe "when decorating gutters", -> diff --git a/spec/text-editor-component-spec.js b/spec/text-editor-component-spec.js index eef49f9f6..b26e64e34 100644 --- a/spec/text-editor-component-spec.js +++ b/spec/text-editor-component-spec.js @@ -1747,11 +1747,13 @@ describe('TextEditorComponent', function () { }) describe('block decorations rendering', function () { + let markerLayer + function createBlockDecorationBeforeScreenRow(screenRow, {className}) { let item = document.createElement("div") item.className = className || "" let blockDecoration = editor.decorateMarker( - editor.markScreenPosition([screenRow, 0], {invalidate: "never"}), + markerLayer.markScreenPosition([screenRow, 0], {invalidate: "never"}), {type: "block", item: item, position: "before"} ) return [item, blockDecoration] @@ -1761,13 +1763,14 @@ describe('TextEditorComponent', function () { let item = document.createElement("div") item.className = className || "" let blockDecoration = editor.decorateMarker( - editor.markScreenPosition([screenRow, 0], {invalidate: "never"}), + markerLayer.markScreenPosition([screenRow, 0], {invalidate: "never"}), {type: "block", item: item, position: "after"} ) return [item, blockDecoration] } beforeEach(function () { + markerLayer = editor.addMarkerLayer() wrapperNode.style.height = 5 * lineHeightInPixels + 'px' editor.update({autoHeight: false}) component.measureDimensions() diff --git a/src/decoration-manager.coffee b/src/decoration-manager.coffee index fefa368d4..2941e3cfd 100644 --- a/src/decoration-manager.coffee +++ b/src/decoration-manager.coffee @@ -71,9 +71,11 @@ class DecorationManager extends Model decorationsForScreenRowRange: (startScreenRow, endScreenRow) -> decorationsByMarkerId = {} - for marker in @defaultMarkerLayer.findMarkers(intersectsScreenRowRange: [startScreenRow, endScreenRow]) - if decorations = @decorationsByMarkerId[marker.id] - decorationsByMarkerId[marker.id] = decorations + for layerId of @decorationCountsByLayerId + layer = @displayLayer.getMarkerLayer(layerId) + for marker in layer.findMarkers(intersectsScreenRowRange: [startScreenRow, endScreenRow]) + if decorations = @decorationsByMarkerId[marker.id] + decorationsByMarkerId[marker.id] = decorations decorationsByMarkerId decorationsStateForScreenRowRange: (startScreenRow, endScreenRow) ->