-
-
Notifications
You must be signed in to change notification settings - Fork 132
/
layer-decoration.js
95 lines (84 loc) · 2.58 KB
/
layer-decoration.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
var idCounter = 0;
var nextId = function() {
return idCounter++;
};
// Essential: Represents a decoration that applies to every marker on a given
// layer. Created via {TextEditor::decorateMarkerLayer}.
module.exports = class LayerDecoration {
constructor(markerLayer, decorationManager, properties1) {
this.markerLayer = markerLayer;
this.decorationManager = decorationManager;
this.properties = properties1;
this.id = nextId();
this.destroyed = false;
this.markerLayerDestroyedDisposable = this.markerLayer.onDidDestroy(() => this.destroy());
this.overridePropertiesByMarker = null;
}
// Essential: Destroys the decoration.
destroy() {
if (this.destroyed) {
return;
}
this.markerLayerDestroyedDisposable.dispose();
this.markerLayerDestroyedDisposable = null;
this.destroyed = true;
this.decorationManager.didDestroyLayerDecoration(this);
}
// Essential: Determine whether this decoration is destroyed.
//
// Returns a {Boolean}.
isDestroyed() {
return this.destroyed;
}
getId() {
return this.id;
}
getMarkerLayer() {
return this.markerLayer;
}
// Essential: Get this decoration's properties.
//
// Returns an {Object}.
getProperties() {
return this.properties;
}
// Essential: Set this decoration's properties.
//
// * `newProperties` See {TextEditor::decorateMarker} for more information on
// the properties. The `type` of `gutter` and `overlay` are not supported on
// layer decorations.
setProperties(newProperties) {
if (this.destroyed) {
return;
}
this.properties = newProperties;
this.decorationManager.emitDidUpdateDecorations();
}
// Essential: Override the decoration properties for a specific marker.
//
// * `marker` The {DisplayMarker} or {Marker} for which to override
// properties.
// * `properties` An {Object} containing properties to apply to this marker.
// Pass `null` to clear the override.
setPropertiesForMarker(marker, properties) {
if (this.destroyed) {
return;
}
if (this.overridePropertiesByMarker == null) {
this.overridePropertiesByMarker = new Map();
}
marker = this.markerLayer.getMarker(marker.id);
if (properties != null) {
this.overridePropertiesByMarker.set(marker, properties);
} else {
this.overridePropertiesByMarker.delete(marker);
}
this.decorationManager.emitDidUpdateDecorations();
}
getPropertiesForMarker(marker) {
if (!this.overridePropertiesByMarker) {
return undefined;
}
return this.overridePropertiesByMarker.get(marker);
}
};