forked from atom/atom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgutter.js
113 lines (98 loc) · 3.28 KB
/
gutter.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
const {Emitter} = require('event-kit')
const DefaultPriority = -100
// Extended: Represents a gutter within a {TextEditor}.
//
// See {TextEditor::addGutter} for information on creating a gutter.
module.exports = class Gutter {
constructor (gutterContainer, options) {
this.gutterContainer = gutterContainer
this.name = options && options.name
this.priority = (options && options.priority != null) ? options.priority : DefaultPriority
this.visible = (options && options.visible != null) ? options.visible : true
this.type = (options && options.type != null) ? options.type : 'decorated'
this.labelFn = options && options.labelFn
this.className = options && options.class
this.onMouseDown = options && options.onMouseDown
this.onMouseMove = options && options.onMouseMove
this.emitter = new Emitter()
}
/*
Section: Gutter Destruction
*/
// Essential: Destroys the gutter.
destroy () {
if (this.name === 'line-number') {
throw new Error('The line-number gutter cannot be destroyed.')
} else {
this.gutterContainer.removeGutter(this)
this.emitter.emit('did-destroy')
this.emitter.dispose()
}
}
/*
Section: Event Subscription
*/
// Essential: Calls your `callback` when the gutter's visibility changes.
//
// * `callback` {Function}
// * `gutter` The gutter whose visibility changed.
//
// Returns a {Disposable} on which `.dispose()` can be called to unsubscribe.
onDidChangeVisible (callback) {
return this.emitter.on('did-change-visible', callback)
}
// Essential: Calls your `callback` when the gutter is destroyed.
//
// * `callback` {Function}
//
// Returns a {Disposable} on which `.dispose()` can be called to unsubscribe.
onDidDestroy (callback) {
return this.emitter.once('did-destroy', callback)
}
/*
Section: Visibility
*/
// Essential: Hide the gutter.
hide () {
if (this.visible) {
this.visible = false
this.gutterContainer.scheduleComponentUpdate()
this.emitter.emit('did-change-visible', this)
}
}
// Essential: Show the gutter.
show () {
if (!this.visible) {
this.visible = true
this.gutterContainer.scheduleComponentUpdate()
this.emitter.emit('did-change-visible', this)
}
}
// Essential: Determine whether the gutter is visible.
//
// Returns a {Boolean}.
isVisible () {
return this.visible
}
// Essential: Add a decoration that tracks a {DisplayMarker}. When the marker moves,
// is invalidated, or is destroyed, the decoration will be updated to reflect
// the marker's state.
//
// ## Arguments
//
// * `marker` A {DisplayMarker} you want this decoration to follow.
// * `decorationParams` An {Object} representing the decoration. It is passed
// to {TextEditor::decorateMarker} as its `decorationParams` and so supports
// all options documented there.
// * `type` __Caveat__: set to `'line-number'` if this is the line-number
// gutter, `'gutter'` otherwise. This cannot be overridden.
//
// Returns a {Decoration} object
decorateMarker (marker, options) {
return this.gutterContainer.addGutterDecoration(this, marker, options)
}
getElement () {
if (this.element == null) this.element = document.createElement('div')
return this.element
}
}