diff --git a/lib/ace/edit_session/bracket_match.js b/lib/ace/edit_session/bracket_match.js index 825f6924..f3923b18 100644 --- a/lib/ace/edit_session/bracket_match.js +++ b/lib/ace/edit_session/bracket_match.js @@ -102,7 +102,7 @@ function BracketMatch() { "}": "{" }; - this.$findOpeningBracket = function(bracket, position, typeRe) { + this.$findOpeningBracket = function(bracket, position, type) { var openBracket = this.$brackets[bracket]; var depth = 1; @@ -113,20 +113,14 @@ function BracketMatch() { if (!token) return; - if (!typeRe){ - typeRe = new RegExp( - "(\\.?" + - token.type.replace(".", "\\.").replace("rparen", ".paren") - + ")+" - ); - } + if (!type) + type = token.type.replace(/\.(?:rparen|lparen|start|end)$/, ""); // Start searching in token, just before the character at position.column var valueIndex = position.column - iterator.getCurrentTokenColumn() - 2; var value = token.value; - while (true) { - + while (true) { while (valueIndex >= 0) { var chr = value.charAt(valueIndex); if (chr == openBracket) { @@ -146,7 +140,7 @@ function BracketMatch() { // whose type matches typeRe do { token = iterator.stepBackward(); - } while (token && !typeRe.test(token.type)); + } while (token && token.type.lastIndexOf(type, 0)); if (token == null) break; @@ -158,7 +152,7 @@ function BracketMatch() { return null; }; - this.$findClosingBracket = function(bracket, position, typeRe) { + this.$findClosingBracket = function(bracket, position, type) { var closingBracket = this.$brackets[bracket]; var depth = 1; @@ -169,19 +163,13 @@ function BracketMatch() { if (!token) return; - if (!typeRe){ - typeRe = new RegExp( - "(\\.?" + - token.type.replace(".", "\\.").replace("lparen", ".paren") - + ")+" - ); - } + if (!type) + type = token.type.replace(/\.(?:rparen|lparen|start|end)$/, ""); // Start searching in token, after the character at position.column var valueIndex = position.column - iterator.getCurrentTokenColumn(); while (true) { - var value = token.value; var valueLength = value.length; while (valueIndex < valueLength) { @@ -203,7 +191,7 @@ function BracketMatch() { // whose type matches typeRe do { token = iterator.stepForward(); - } while (token && !typeRe.test(token.type)); + } while (token && token.type.lastIndexOf(type, 0)); if (token == null) break; diff --git a/lib/ace/keyboard/vim/maps/motions.js b/lib/ace/keyboard/vim/maps/motions.js index 91c8b8af..5fdfe955 100644 --- a/lib/ace/keyboard/vim/maps/motions.js +++ b/lib/ace/keyboard/vim/maps/motions.js @@ -355,10 +355,10 @@ module.exports = { case "{": case "[": var cursor = editor.getCursorPosition(); - var end = editor.session.$findClosingBracket(param, cursor, /paren/); + var end = editor.session.$findClosingBracket(param, cursor, "paren"); if (!end) return; - var start = editor.session.$findOpeningBracket(editor.session.$brackets[param], cursor, /paren/); + var start = editor.session.$findOpeningBracket(editor.session.$brackets[param], cursor, "paren"); if (!start) return; end.column ++;