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);
11 cm.on("cursorActivity", doMatchTags);
12 cm.on("viewportChange", maybeUpdateMatch);
18 if (cm.state.matchedTag) {
19 cm.state.matchedTag.clear();
20 cm.state.matchedTag = null;
24 function doMatchTags(cm) {
25 cm.state.failedTagMatch = false;
26 cm.operation(function() {
28 var cur = cm.getCursor(), range = cm.getViewport();
29 range.from = Math.min(range.from, cur.line); range.to = Math.max(cur.line + 1, range.to);
30 var match = CodeMirror.findMatchingTag(cm, cur, range);
32 var other = match.at == "close" ? match.open : match.close;
34 cm.state.matchedTag = cm.markText(other.from, other.to, {className: "CodeMirror-matchingtag"});
36 cm.state.failedTagMatch = true;
40 function maybeUpdateMatch(cm) {
41 if (cm.state.failedTagMatch) doMatchTags(cm);
44 CodeMirror.commands.toMatchingTag = function(cm) {
45 var found = CodeMirror.findMatchingTag(cm, cm.getCursor());
47 var other = found.at == "close" ? found.open : found.close;
48 if (other) cm.setSelection(other.to, other.from);