From 88984d2965dce38bae6bdff67635206dd4aa7ae1 Mon Sep 17 00:00:00 2001 From: Thiemo Kreuz Date: Thu, 14 Jan 2021 11:01:58 +0100 Subject: [PATCH] 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 --- .../codemirror/addon/edit/matchbrackets.js | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/resources/lib/codemirror/addon/edit/matchbrackets.js b/resources/lib/codemirror/addon/edit/matchbrackets.js index 0c565814..2fa02b2e 100644 --- a/resources/lib/codemirror/addon/edit/matchbrackets.js +++ b/resources/lib/codemirror/addon/edit/matchbrackets.js @@ -33,7 +33,7 @@ return config && config.bracketRegex || /[(){}[\]]/ } - var brackets = { + var surroundingBrackets = { '(': ')', ')': false, '[': ']', @@ -43,12 +43,12 @@ }; function findSurroundingBrackets( cm, where, config ) { - var i, from, to, ch, + var from, to, ch, nestedBracketsToSkip = 0, lineNo = where.line, line = cm.getLine( lineNo ), pos = where.ch, - maxScanLen = ( config && config.maxScanLineLength ) || 10000; + maxScanLen = ( config && config.maxScanLineLength ) || 10000, maxScanLines = ( config && config.maxScanLines ) || 1000; // Check the limit for the current line @@ -75,13 +75,13 @@ } ch = line.charAt( pos ); - if ( ch in brackets ) { + if ( ch in surroundingBrackets ) { // 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 }; break; } - nestedBracketsToSkip += brackets[ch] ? 1 : -1; + nestedBracketsToSkip += surroundingBrackets[ch] ? 1 : -1; } pos++; @@ -112,13 +112,13 @@ } ch = line.charAt( pos ); - if ( ch in brackets ) { + if ( ch in surroundingBrackets ) { // Found an opening bracket that's not part of a nested pair - if ( brackets[ch] && nestedBracketsToSkip <= 0 ) { - from = { pos: Pos( lineNo, pos ), expectedToChar: brackets[ch] }; + if ( surroundingBrackets[ch] && nestedBracketsToSkip <= 0 ) { + from = { pos: Pos( lineNo, pos ), expectedToChar: surroundingBrackets[ch] }; break; } - nestedBracketsToSkip += brackets[ch] ? -1 : 1; + nestedBracketsToSkip += surroundingBrackets[ch] ? -1 : 1; } } @@ -128,13 +128,11 @@ to: to.pos, match: from.expectedToChar === to.char }; - } else if ( from ) { - return { from: from.pos, match: false }; - } else if ( to ) { - return { from: to.pos, match: false }; - } else { - return null; + } else if ( from || to ) { + return { from: ( from || to ).pos, match: false }; } + + return null; } function findMatchingBracket(cm, where, config) {