Skip to content

Commit 156e668

Browse files
blittleadrianheine
authored andcommitted
Fix matchBrackets to work with multiple cm instances
1 parent ef23413 commit 156e668

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

addon/edit/matchbrackets.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,23 @@
102102
}
103103
}
104104

105-
var currentlyHighlighted = null;
106105
function doMatchBrackets(cm) {
107106
cm.operation(function() {
108-
if (currentlyHighlighted) {currentlyHighlighted(); currentlyHighlighted = null;}
109-
currentlyHighlighted = matchBrackets(cm, false, cm.state.matchBrackets);
107+
if (cm.state.matchBrackets.currentlyHighlighted) {
108+
cm.state.matchBrackets.currentlyHighlighted();
109+
cm.state.matchBrackets.currentlyHighlighted = null;
110+
}
111+
cm.state.matchBrackets.currentlyHighlighted = matchBrackets(cm, false, cm.state.matchBrackets);
110112
});
111113
}
112114

113115
CodeMirror.defineOption("matchBrackets", false, function(cm, val, old) {
114116
if (old && old != CodeMirror.Init) {
115117
cm.off("cursorActivity", doMatchBrackets);
116-
if (currentlyHighlighted) {currentlyHighlighted(); currentlyHighlighted = null;}
118+
if (cm.state.matchBrackets && cm.state.matchBrackets.currentlyHighlighted) {
119+
cm.state.matchBrackets.currentlyHighlighted();
120+
cm.state.matchBrackets.currentlyHighlighted = null;
121+
}
117122
}
118123
if (val) {
119124
cm.state.matchBrackets = typeof val == "object" ? val : {};

0 commit comments

Comments
 (0)