forked from deathau/cm-show-whitespace-obsidian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcm-show-invisibles.js
44 lines (44 loc) · 1.22 KB
/
cm-show-invisibles.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
CodeMirror.defineOption('showInvisibles', false, (cm, val, prev) => {
let Count = 0;
const Maximum = cm.getOption('maxInvisibles') || 16;
if (prev === CodeMirror.Init)
prev = false;
if (prev && !val) {
cm.removeOverlay('invisibles');
return;
}
if (!prev && val) {
//add(Maximum);
cm.addOverlay({
name: 'invisibles',
token: function nextToken(stream) {
let spaces = 0;
let peek = stream.peek() === ' ';
if (peek) {
while (peek && spaces < Maximum) {
++spaces;
stream.next();
peek = stream.peek() === ' ';
}
let ret = 'whitespace whitespace-' + spaces;
/*
* styles should be different
* could not be two same styles
* beside because of this check in runmode
* function in `codemirror.js`:
*
* 6624: if (!flattenSpans || curStyle != style) {}
*/
if (spaces === Maximum)
ret += ' whitespace-rand-' + Count++;
return ret;
}
while (!stream.eol() && !peek) {
stream.next();
peek = stream.peek() === ' ';
}
return 'cm-eol';
},
});
}
});