mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CodeMirror
synced 2024-11-15 02:04:02 +00:00
Fix minor code style issues in matchbrackets addon
Less ambiguous variable names. Less duplication. The minor issues have been introduced in T270317. Bug: T270317 Change-Id: I366396a61b76e19293ce8d14c2f346b97498fe40
This commit is contained in:
parent
0bebeea02f
commit
88984d2965
|
@ -33,7 +33,7 @@
|
||||||
return config && config.bracketRegex || /[(){}[\]]/
|
return config && config.bracketRegex || /[(){}[\]]/
|
||||||
}
|
}
|
||||||
|
|
||||||
var brackets = {
|
var surroundingBrackets = {
|
||||||
'(': ')',
|
'(': ')',
|
||||||
')': false,
|
')': false,
|
||||||
'[': ']',
|
'[': ']',
|
||||||
|
@ -43,12 +43,12 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
function findSurroundingBrackets( cm, where, config ) {
|
function findSurroundingBrackets( cm, where, config ) {
|
||||||
var i, from, to, ch,
|
var from, to, ch,
|
||||||
nestedBracketsToSkip = 0,
|
nestedBracketsToSkip = 0,
|
||||||
lineNo = where.line,
|
lineNo = where.line,
|
||||||
line = cm.getLine( lineNo ),
|
line = cm.getLine( lineNo ),
|
||||||
pos = where.ch,
|
pos = where.ch,
|
||||||
maxScanLen = ( config && config.maxScanLineLength ) || 10000;
|
maxScanLen = ( config && config.maxScanLineLength ) || 10000,
|
||||||
maxScanLines = ( config && config.maxScanLines ) || 1000;
|
maxScanLines = ( config && config.maxScanLines ) || 1000;
|
||||||
|
|
||||||
// Check the limit for the current line
|
// Check the limit for the current line
|
||||||
|
@ -75,13 +75,13 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
ch = line.charAt( pos );
|
ch = line.charAt( pos );
|
||||||
if ( ch in brackets ) {
|
if ( ch in surroundingBrackets ) {
|
||||||
// Found a closing bracket that's not part of a nested pair
|
// Found a closing bracket that's not part of a nested pair
|
||||||
if ( !brackets[ch] && nestedBracketsToSkip <= 0 ) {
|
if ( !surroundingBrackets[ch] && nestedBracketsToSkip <= 0 ) {
|
||||||
to = { pos: Pos( lineNo, pos ), char: ch };
|
to = { pos: Pos( lineNo, pos ), char: ch };
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
nestedBracketsToSkip += brackets[ch] ? 1 : -1;
|
nestedBracketsToSkip += surroundingBrackets[ch] ? 1 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos++;
|
pos++;
|
||||||
|
@ -112,13 +112,13 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
ch = line.charAt( pos );
|
ch = line.charAt( pos );
|
||||||
if ( ch in brackets ) {
|
if ( ch in surroundingBrackets ) {
|
||||||
// Found an opening bracket that's not part of a nested pair
|
// Found an opening bracket that's not part of a nested pair
|
||||||
if ( brackets[ch] && nestedBracketsToSkip <= 0 ) {
|
if ( surroundingBrackets[ch] && nestedBracketsToSkip <= 0 ) {
|
||||||
from = { pos: Pos( lineNo, pos ), expectedToChar: brackets[ch] };
|
from = { pos: Pos( lineNo, pos ), expectedToChar: surroundingBrackets[ch] };
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
nestedBracketsToSkip += brackets[ch] ? -1 : 1;
|
nestedBracketsToSkip += surroundingBrackets[ch] ? -1 : 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,13 +128,11 @@
|
||||||
to: to.pos,
|
to: to.pos,
|
||||||
match: from.expectedToChar === to.char
|
match: from.expectedToChar === to.char
|
||||||
};
|
};
|
||||||
} else if ( from ) {
|
} else if ( from || to ) {
|
||||||
return { from: from.pos, match: false };
|
return { from: ( from || to ).pos, match: false };
|
||||||
} else if ( to ) {
|
|
||||||
return { from: to.pos, match: false };
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function findMatchingBracket(cm, where, config) {
|
function findMatchingBracket(cm, where, config) {
|
||||||
|
|
Loading…
Reference in a new issue