Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 57b5ce0

Browse files
author
Antonio Scandurra
authored
Merge pull request #229 from atom/revert-228-as-ns-scope-ids
Revert "Support multiple text decoration layers and provide a built-in one based on markers"
2 parents 225bc41 + ab772e7 commit 57b5ce0

12 files changed

+295
-862
lines changed

spec/display-layer-spec.js

Lines changed: 97 additions & 240 deletions
Large diffs are not rendered by default.

spec/helpers/test-decoration-layer.js

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
const {MarkerIndex} = require('superstring')
2+
const {Emitter} = require('event-kit')
3+
const Point = require('../../src/point')
4+
const Range = require('../../src/range')
5+
const {MAX_BUILT_IN_SCOPE_ID} = require('../../src/constants')
6+
7+
module.exports =
8+
class TestDecorationLayer {
9+
constructor (decorations, buffer, random) {
10+
this.buffer = buffer
11+
this.random = random
12+
this.nextMarkerId = MAX_BUILT_IN_SCOPE_ID + 1
13+
this.markerIndex = new MarkerIndex()
14+
this.classNamesByScopeId = new Map()
15+
this.emitter = new Emitter()
16+
17+
for (let value of decorations) {
18+
const className = value[0]
19+
const [rangeStart, rangeEnd] = Array.from(value[1])
20+
const markerId = this.getNextMarkerId()
21+
this.markerIndex.insert(markerId, Point.fromObject(rangeStart), Point.fromObject(rangeEnd))
22+
this.classNamesByScopeId.set(markerId, className)
23+
}
24+
25+
if (this.buffer) {
26+
this.buffer.registerTextDecorationLayer(this)
27+
}
28+
}
29+
30+
getNextMarkerId () {
31+
const nextMarkerId = this.nextMarkerId
32+
this.nextMarkerId += 2
33+
return nextMarkerId
34+
}
35+
36+
classNameForScopeId (scopeId) {
37+
return this.classNamesByScopeId.get(scopeId)
38+
}
39+
40+
buildIterator () {
41+
return new TestDecorationLayerIterator(this)
42+
}
43+
44+
getInvalidatedRanges () { return this.invalidatedRanges }
45+
46+
onDidInvalidateRange (fn) {
47+
return this.emitter.on('did-invalidate-range', fn)
48+
}
49+
50+
emitInvalidateRangeEvent (range) {
51+
return this.emitter.emit('did-invalidate-range', range)
52+
}
53+
54+
bufferDidChange ({oldRange, newRange}) {
55+
this.invalidatedRanges = [Range.fromObject(newRange)]
56+
const {inside, overlap} = this.markerIndex.splice(oldRange.start, oldRange.getExtent(), newRange.getExtent())
57+
overlap.forEach((id) => this.invalidatedRanges.push(this.markerIndex.getRange(id)))
58+
inside.forEach((id) => this.invalidatedRanges.push(this.markerIndex.getRange(id)))
59+
60+
this.insertRandomDecorations(oldRange, newRange)
61+
}
62+
63+
insertRandomDecorations (oldRange, newRange) {
64+
if (this.invalidatedRanges == null) { this.invalidatedRanges = [] }
65+
66+
const j = this.random(5)
67+
for (let i = 0; i < j; i++) {
68+
const markerId = this.getNextMarkerId()
69+
const className = String.fromCharCode('a'.charCodeAt(0) + this.random(27))
70+
this.classNamesByScopeId.set(markerId, className)
71+
const range = this.getRandomRangeCloseTo(oldRange.union(newRange))
72+
this.markerIndex.insert(markerId, range.start, range.end)
73+
this.invalidatedRanges.push(range)
74+
}
75+
}
76+
77+
getRandomRangeCloseTo (range) {
78+
let minRow
79+
if (this.random(10) < 7) {
80+
minRow = this.constrainRow(range.start.row + this.random.intBetween(-20, 20))
81+
} else {
82+
minRow = 0
83+
}
84+
85+
let maxRow
86+
if (this.random(10) < 7) {
87+
maxRow = this.constrainRow(range.end.row + this.random.intBetween(-20, 20))
88+
} else {
89+
maxRow = this.buffer.getLastRow()
90+
}
91+
92+
const startRow = this.random.intBetween(minRow, maxRow)
93+
const endRow = this.random.intBetween(startRow, maxRow)
94+
const startColumn = this.random(this.buffer.lineForRow(startRow).length + 1)
95+
const endColumn = this.random(this.buffer.lineForRow(endRow).length + 1)
96+
return Range(Point(startRow, startColumn), Point(endRow, endColumn))
97+
}
98+
99+
constrainRow (row) {
100+
return Math.max(0, Math.min(this.buffer.getLastRow(), row))
101+
}
102+
}
103+
104+
class TestDecorationLayerIterator {
105+
constructor (layer) {
106+
this.layer = layer
107+
}
108+
109+
seek (position) {
110+
const {containingStart, boundaries} = this.layer.markerIndex.findBoundariesAfter(position, Number.MAX_SAFE_INTEGER)
111+
this.boundaries = boundaries
112+
this.boundaryIndex = 0
113+
return containingStart
114+
}
115+
116+
moveToSuccessor () {
117+
return this.boundaryIndex++
118+
}
119+
120+
getPosition () {
121+
const boundary = this.boundaries[this.boundaryIndex]
122+
return boundary ? boundary.position : Point.INFINITY
123+
}
124+
125+
getCloseScopeIds () {
126+
const result = []
127+
const boundary = this.boundaries[this.boundaryIndex]
128+
if (boundary) {
129+
boundary.ending.forEach((markerId) => {
130+
if (!boundary.starting.has(markerId)) {
131+
result.push(markerId)
132+
}
133+
})
134+
}
135+
return result
136+
}
137+
138+
getOpenScopeIds () {
139+
const result = []
140+
const boundary = this.boundaries[this.boundaryIndex]
141+
if (boundary) {
142+
boundary.starting.forEach((markerId) => {
143+
if (!boundary.ending.has(markerId)) {
144+
result.push(markerId)
145+
}
146+
})
147+
}
148+
return result
149+
}
150+
}

spec/marker-layer-spec.coffee

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{uniq, times} = require 'underscore-plus'
22
TextBuffer = require '../src/text-buffer'
3-
Point = require '../src/point'
43

54
describe "MarkerLayer", ->
65
[buffer, layer1, layer2] = []

spec/marker-text-decoration-layer-spec.js

Lines changed: 0 additions & 198 deletions
This file was deleted.

0 commit comments

Comments
 (0)