Skip to content

Commit 4823ade

Browse files
authored
[matchbrackets addon] Add highlightNonMatching option
It's not uncommon to have non-matching brackets in MediaWiki wikitext source code. This is not always an error. Another reason why we want to disable this feature is that it's rather distracting while typing. We temporarily patched our copy of the addon, but think it's worth having a proper config flag. https://gerrit.wikimedia.org/r/656119
1 parent 8d13f24 commit 4823ade

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

addon/edit/matchbrackets.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,12 @@
8080

8181
function matchBrackets(cm, autoclear, config) {
8282
// Disable brace matching in long lines, since it'll cause hugely slow updates
83-
var maxHighlightLen = cm.state.matchBrackets.maxHighlightLineLength || 1000;
83+
var maxHighlightLen = cm.state.matchBrackets.maxHighlightLineLength || 1000,
84+
highlightNonMatching = config && config.highlightNonMatching;
8485
var marks = [], ranges = cm.listSelections();
8586
for (var i = 0; i < ranges.length; i++) {
8687
var match = ranges[i].empty() && findMatchingBracket(cm, ranges[i].head, config);
87-
if (match && cm.getLine(match.from.line).length <= maxHighlightLen) {
88+
if (match && (match.match || highlightNonMatching !== false) && cm.getLine(match.from.line).length <= maxHighlightLen) {
8889
var style = match.match ? "CodeMirror-matchingbracket" : "CodeMirror-nonmatchingbracket";
8990
marks.push(cm.markText(match.from, Pos(match.from.line, match.from.ch + 1), {className: style}));
9091
if (match.to && cm.getLine(match.to.line).length <= maxHighlightLen)

doc/manual.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2443,6 +2443,8 @@ <h2 id="addons">Addons</h2>
24432443
<dl>
24442444
<dt><strong><code>afterCursor</code></strong></dt>
24452445
<dd>Only use the character after the start position, never the one before it.</dd>
2446+
<dt><strong><code>highlightNonMatching</code></strong></dt>
2447+
<dd>Also highlight pairs of non-matching as well as stray brackets. Enabled by default.</dd>
24462448
<dt><strong><code>strict</code></strong></dt>
24472449
<dd>Causes only matches where both brackets are at the same side of the start position to be considered.</dd>
24482450
<dt><strong><code>maxScanLines</code></strong></dt>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy