mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-10 10:17:11 +03:00
Make decorationsForScreenRowRange return all decorations
Even if they are for markers that aren't on the default marker layer
This commit is contained in:
parent
edc9745018
commit
28508d9a3f
@ -1,12 +1,13 @@
|
|||||||
DecorationManager = require '../src/decoration-manager'
|
DecorationManager = require '../src/decoration-manager'
|
||||||
|
|
||||||
describe "DecorationManager", ->
|
describe "DecorationManager", ->
|
||||||
[decorationManager, buffer, defaultMarkerLayer, displayLayer] = []
|
[decorationManager, buffer, defaultMarkerLayer, displayLayer, otherMarkerLayer] = []
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
buffer = atom.project.bufferForPathSync('sample.js')
|
buffer = atom.project.bufferForPathSync('sample.js')
|
||||||
displayLayer = buffer.addDisplayLayer()
|
displayLayer = buffer.addDisplayLayer()
|
||||||
defaultMarkerLayer = displayLayer.addMarkerLayer()
|
defaultMarkerLayer = displayLayer.addMarkerLayer()
|
||||||
|
otherMarkerLayer = displayLayer.addMarkerLayer()
|
||||||
decorationManager = new DecorationManager(displayLayer, defaultMarkerLayer)
|
decorationManager = new DecorationManager(displayLayer, defaultMarkerLayer)
|
||||||
|
|
||||||
waitsForPromise ->
|
waitsForPromise ->
|
||||||
@ -17,21 +18,29 @@ describe "DecorationManager", ->
|
|||||||
buffer.release()
|
buffer.release()
|
||||||
|
|
||||||
describe "decorations", ->
|
describe "decorations", ->
|
||||||
[marker, decoration, decorationProperties] = []
|
[marker, layerMarker, decoration, layerMarkerDecoration, decorationProperties] = []
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
marker = defaultMarkerLayer.markBufferRange([[2, 13], [3, 15]])
|
marker = defaultMarkerLayer.markBufferRange([[2, 13], [3, 15]])
|
||||||
decorationProperties = {type: 'line-number', class: 'one'}
|
decorationProperties = {type: 'line-number', class: 'one'}
|
||||||
decoration = decorationManager.decorateMarker(marker, decorationProperties)
|
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", ->
|
it "can add decorations associated with markers and remove them", ->
|
||||||
expect(decoration).toBeDefined()
|
expect(decoration).toBeDefined()
|
||||||
expect(decoration.getProperties()).toBe decorationProperties
|
expect(decoration.getProperties()).toBe decorationProperties
|
||||||
expect(decorationManager.decorationForId(decoration.id)).toBe decoration
|
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()
|
decoration.destroy()
|
||||||
expect(decorationManager.decorationsForScreenRowRange(2, 3)[marker.id]).not.toBeDefined()
|
expect(decorationManager.decorationsForScreenRowRange(2, 3)[marker.id]).not.toBeDefined()
|
||||||
expect(decorationManager.decorationForId(decoration.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", ->
|
it "will not fail if the decoration is removed twice", ->
|
||||||
decoration.destroy()
|
decoration.destroy()
|
||||||
@ -63,9 +72,9 @@ describe "DecorationManager", ->
|
|||||||
|
|
||||||
describe "::getDecorations(properties)", ->
|
describe "::getDecorations(properties)", ->
|
||||||
it "returns decorations matching the given optional 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: 'two').length).toEqual 0
|
||||||
expect(decorationManager.getDecorations(class: 'one').length).toEqual 1
|
expect(decorationManager.getDecorations(class: 'one').length).toEqual 2
|
||||||
|
|
||||||
describe "::decorateMarker", ->
|
describe "::decorateMarker", ->
|
||||||
describe "when decorating gutters", ->
|
describe "when decorating gutters", ->
|
||||||
|
@ -1747,11 +1747,13 @@ describe('TextEditorComponent', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('block decorations rendering', function () {
|
describe('block decorations rendering', function () {
|
||||||
|
let markerLayer
|
||||||
|
|
||||||
function createBlockDecorationBeforeScreenRow(screenRow, {className}) {
|
function createBlockDecorationBeforeScreenRow(screenRow, {className}) {
|
||||||
let item = document.createElement("div")
|
let item = document.createElement("div")
|
||||||
item.className = className || ""
|
item.className = className || ""
|
||||||
let blockDecoration = editor.decorateMarker(
|
let blockDecoration = editor.decorateMarker(
|
||||||
editor.markScreenPosition([screenRow, 0], {invalidate: "never"}),
|
markerLayer.markScreenPosition([screenRow, 0], {invalidate: "never"}),
|
||||||
{type: "block", item: item, position: "before"}
|
{type: "block", item: item, position: "before"}
|
||||||
)
|
)
|
||||||
return [item, blockDecoration]
|
return [item, blockDecoration]
|
||||||
@ -1761,13 +1763,14 @@ describe('TextEditorComponent', function () {
|
|||||||
let item = document.createElement("div")
|
let item = document.createElement("div")
|
||||||
item.className = className || ""
|
item.className = className || ""
|
||||||
let blockDecoration = editor.decorateMarker(
|
let blockDecoration = editor.decorateMarker(
|
||||||
editor.markScreenPosition([screenRow, 0], {invalidate: "never"}),
|
markerLayer.markScreenPosition([screenRow, 0], {invalidate: "never"}),
|
||||||
{type: "block", item: item, position: "after"}
|
{type: "block", item: item, position: "after"}
|
||||||
)
|
)
|
||||||
return [item, blockDecoration]
|
return [item, blockDecoration]
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
|
markerLayer = editor.addMarkerLayer()
|
||||||
wrapperNode.style.height = 5 * lineHeightInPixels + 'px'
|
wrapperNode.style.height = 5 * lineHeightInPixels + 'px'
|
||||||
editor.update({autoHeight: false})
|
editor.update({autoHeight: false})
|
||||||
component.measureDimensions()
|
component.measureDimensions()
|
||||||
|
@ -71,9 +71,11 @@ class DecorationManager extends Model
|
|||||||
|
|
||||||
decorationsForScreenRowRange: (startScreenRow, endScreenRow) ->
|
decorationsForScreenRowRange: (startScreenRow, endScreenRow) ->
|
||||||
decorationsByMarkerId = {}
|
decorationsByMarkerId = {}
|
||||||
for marker in @defaultMarkerLayer.findMarkers(intersectsScreenRowRange: [startScreenRow, endScreenRow])
|
for layerId of @decorationCountsByLayerId
|
||||||
if decorations = @decorationsByMarkerId[marker.id]
|
layer = @displayLayer.getMarkerLayer(layerId)
|
||||||
decorationsByMarkerId[marker.id] = decorations
|
for marker in layer.findMarkers(intersectsScreenRowRange: [startScreenRow, endScreenRow])
|
||||||
|
if decorations = @decorationsByMarkerId[marker.id]
|
||||||
|
decorationsByMarkerId[marker.id] = decorations
|
||||||
decorationsByMarkerId
|
decorationsByMarkerId
|
||||||
|
|
||||||
decorationsStateForScreenRowRange: (startScreenRow, endScreenRow) ->
|
decorationsStateForScreenRowRange: (startScreenRow, endScreenRow) ->
|
||||||
|
Loading…
Reference in New Issue
Block a user