Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
51007 views
1
(function() {
2
"use strict";
3
4
CodeMirror.defineOption("matchTags", false, function(cm, val, old) {
5
if (old && old != CodeMirror.Init) {
6
cm.off("cursorActivity", doMatchTags);
7
cm.off("viewportChange", maybeUpdateMatch);
8
clear(cm);
9
}
10
if (val) {
11
cm.state.matchBothTags = typeof val == "object" && val.bothTags;
12
cm.on("cursorActivity", doMatchTags);
13
cm.on("viewportChange", maybeUpdateMatch);
14
doMatchTags(cm);
15
}
16
});
17
18
function clear(cm) {
19
if (cm.state.tagHit) cm.state.tagHit.clear();
20
if (cm.state.tagOther) cm.state.tagOther.clear();
21
cm.state.tagHit = cm.state.tagOther = null;
22
}
23
24
function doMatchTags(cm) {
25
cm.state.failedTagMatch = false;
26
cm.operation(function() {
27
clear(cm);
28
if (cm.somethingSelected()) return;
29
var cur = cm.getCursor(), range = cm.getViewport();
30
range.from = Math.min(range.from, cur.line); range.to = Math.max(cur.line + 1, range.to);
31
var match = CodeMirror.findMatchingTag(cm, cur, range);
32
if (!match) return;
33
if (cm.state.matchBothTags) {
34
var hit = match.at == "open" ? match.open : match.close;
35
if (hit) cm.state.tagHit = cm.markText(hit.from, hit.to, {className: "CodeMirror-matchingtag"});
36
}
37
var other = match.at == "close" ? match.open : match.close;
38
if (other)
39
cm.state.tagOther = cm.markText(other.from, other.to, {className: "CodeMirror-matchingtag"});
40
else
41
cm.state.failedTagMatch = true;
42
});
43
}
44
45
function maybeUpdateMatch(cm) {
46
if (cm.state.failedTagMatch) doMatchTags(cm);
47
}
48
49
CodeMirror.commands.toMatchingTag = function(cm) {
50
var found = CodeMirror.findMatchingTag(cm, cm.getCursor());
51
if (found) {
52
var other = found.at == "close" ? found.open : found.close;
53
if (other) cm.setSelection(other.to, other.from);
54
}
55
};
56
})();
57
58