Changed leading white space to use spaces instead of tabs (no actual code changes, just reformatting the code)
This commit is contained in:
parent
bcabfcb2e2
commit
5030abba97
2 changed files with 173 additions and 173 deletions
|
|
@ -20,7 +20,7 @@
|
||||||
* the Initial Developer. All Rights Reserved.
|
* the Initial Developer. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
* Fabian Jakobs <fabian AT ajax DOT org>
|
* Fabian Jakobs <fabian AT ajax DOT org>
|
||||||
*
|
*
|
||||||
* Alternatively, the contents of this file may be used under the terms of
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
|
@ -42,132 +42,132 @@ var TokenIterator = require("ace/token_iterator").TokenIterator;
|
||||||
|
|
||||||
function BracketMatch() {
|
function BracketMatch() {
|
||||||
|
|
||||||
this.findMatchingBracket = function(position) {
|
this.findMatchingBracket = function(position) {
|
||||||
if (position.column == 0) return null;
|
if (position.column == 0) return null;
|
||||||
|
|
||||||
var charBeforeCursor = this.getLine(position.row).charAt(position.column-1);
|
var charBeforeCursor = this.getLine(position.row).charAt(position.column-1);
|
||||||
if (charBeforeCursor == "") return null;
|
if (charBeforeCursor == "") return null;
|
||||||
|
|
||||||
var match = charBeforeCursor.match(/([\(\[\{])|([\)\]\}])/);
|
var match = charBeforeCursor.match(/([\(\[\{])|([\)\]\}])/);
|
||||||
if (!match) {
|
if (!match) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (match[1]) {
|
if (match[1]) {
|
||||||
return this.$findClosingBracket(match[1], position);
|
return this.$findClosingBracket(match[1], position);
|
||||||
} else {
|
} else {
|
||||||
return this.$findOpeningBracket(match[2], position);
|
return this.$findOpeningBracket(match[2], position);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$brackets = {
|
this.$brackets = {
|
||||||
")": "(",
|
")": "(",
|
||||||
"(": ")",
|
"(": ")",
|
||||||
"]": "[",
|
"]": "[",
|
||||||
"[": "]",
|
"[": "]",
|
||||||
"{": "}",
|
"{": "}",
|
||||||
"}": "{"
|
"}": "{"
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$findOpeningBracket = function(bracket, position) {
|
this.$findOpeningBracket = function(bracket, position) {
|
||||||
var openBracket = this.$brackets[bracket];
|
var openBracket = this.$brackets[bracket];
|
||||||
var depth = 1;
|
var depth = 1;
|
||||||
|
|
||||||
var iterator = new TokenIterator(this, position.row, position.column);
|
var iterator = new TokenIterator(this, position.row, position.column);
|
||||||
var token = iterator.getCurrentToken();
|
var token = iterator.getCurrentToken();
|
||||||
if (!token) return null;
|
if (!token) return null;
|
||||||
|
|
||||||
// Create a pattern that matches any token with the same type as token.type.
|
// Create a pattern that matches any token with the same type as token.type.
|
||||||
// Exception: if token.type includes "rparen", then also match "lparen".
|
// Exception: if token.type includes "rparen", then also match "lparen".
|
||||||
var typeRe = new RegExp("(\\.?[" +
|
var typeRe = new RegExp("(\\.?[" +
|
||||||
token.type.replace(".", "|").replace("rparen", "lparen|rparen") + "])+");
|
token.type.replace(".", "|").replace("rparen", "lparen|rparen") + "])+");
|
||||||
|
|
||||||
// Start searching in token, just before the character at position.column
|
// Start searching in token, just before the character at position.column
|
||||||
var vIndex = position.column - iterator.getCurrentTokenColumn() - 2;
|
var vIndex = position.column - iterator.getCurrentTokenColumn() - 2;
|
||||||
var value = token.value;
|
var value = token.value;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
||||||
while (vIndex >= 0) {
|
while (vIndex >= 0) {
|
||||||
var char = value.charAt(vIndex);
|
var char = value.charAt(vIndex);
|
||||||
if (char == openBracket) {
|
if (char == openBracket) {
|
||||||
depth -= 1;
|
depth -= 1;
|
||||||
if (depth == 0) {
|
if (depth == 0) {
|
||||||
return {row: iterator.getCurrentTokenRow(),
|
return {row: iterator.getCurrentTokenRow(),
|
||||||
column: vIndex + iterator.getCurrentTokenColumn()};
|
column: vIndex + iterator.getCurrentTokenColumn()};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (char == bracket) {
|
else if (char == bracket) {
|
||||||
depth += 1;
|
depth += 1;
|
||||||
}
|
}
|
||||||
vIndex -= 1;
|
vIndex -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scan backward through the document, looking for the next token
|
// Scan backward through the document, looking for the next token
|
||||||
// whose type matches typeRe
|
// whose type matches typeRe
|
||||||
do {
|
do {
|
||||||
token = iterator.stepBackward();
|
token = iterator.stepBackward();
|
||||||
} while (token && !typeRe.test(token.type))
|
} while (token && !typeRe.test(token.type))
|
||||||
|
|
||||||
if (token == null)
|
if (token == null)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
value = token.value;
|
value = token.value;
|
||||||
vIndex = token.value.length - 1;
|
vIndex = token.value.length - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$findClosingBracket = function(bracket, position) {
|
this.$findClosingBracket = function(bracket, position) {
|
||||||
var closingBracket = this.$brackets[bracket];
|
var closingBracket = this.$brackets[bracket];
|
||||||
var depth = 1;
|
var depth = 1;
|
||||||
|
|
||||||
var iterator = new TokenIterator(this, position.row, position.column);
|
var iterator = new TokenIterator(this, position.row, position.column);
|
||||||
var token = iterator.getCurrentToken();
|
var token = iterator.getCurrentToken();
|
||||||
if (!token) return null;
|
if (!token) return null;
|
||||||
|
|
||||||
// Create a pattern that matches any token with the same type as token.type.
|
// Create a pattern that matches any token with the same type as token.type.
|
||||||
// Exception: if token.type includes "lparen", then also match "rparen".
|
// Exception: if token.type includes "lparen", then also match "rparen".
|
||||||
var typeRe = new RegExp("(\\.?[" +
|
var typeRe = new RegExp("(\\.?[" +
|
||||||
token.type.replace(".", "|").replace("lparen", "lparen|rparen") + "])+");
|
token.type.replace(".", "|").replace("lparen", "lparen|rparen") + "])+");
|
||||||
|
|
||||||
// Start searching in token, after after the character at position.column
|
// Start searching in token, after after the character at position.column
|
||||||
var vIndex = position.column - iterator.getCurrentTokenColumn();
|
var vIndex = position.column - iterator.getCurrentTokenColumn();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
||||||
var value = token.value;
|
var value = token.value;
|
||||||
var valueLength = value.length;
|
var valueLength = value.length;
|
||||||
while (vIndex < valueLength) {
|
while (vIndex < valueLength) {
|
||||||
var char = value.charAt(vIndex);
|
var char = value.charAt(vIndex);
|
||||||
if (char == closingBracket) {
|
if (char == closingBracket) {
|
||||||
depth -= 1;
|
depth -= 1;
|
||||||
if (depth == 0) {
|
if (depth == 0) {
|
||||||
return {row: iterator.getCurrentTokenRow(),
|
return {row: iterator.getCurrentTokenRow(),
|
||||||
column: vIndex + iterator.getCurrentTokenColumn()};
|
column: vIndex + iterator.getCurrentTokenColumn()};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (char == bracket) {
|
else if (char == bracket) {
|
||||||
depth += 1;
|
depth += 1;
|
||||||
}
|
}
|
||||||
vIndex += 1;
|
vIndex += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scan forward through the document, looking for the next token
|
// Scan forward through the document, looking for the next token
|
||||||
// whose type matches typeRe
|
// whose type matches typeRe
|
||||||
do {
|
do {
|
||||||
token = iterator.stepForward();
|
token = iterator.stepForward();
|
||||||
} while (token && !typeRe.test(token.type))
|
} while (token && !typeRe.test(token.type))
|
||||||
|
|
||||||
if (token == null)
|
if (token == null)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
vIndex = 0;
|
vIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
exports.BracketMatch = BracketMatch;
|
exports.BracketMatch = BracketMatch;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
* the Initial Developer. All Rights Reserved.
|
* the Initial Developer. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
* Fabian Jakobs <fabian AT ajax DOT org>
|
* Fabian Jakobs <fabian AT ajax DOT org>
|
||||||
*
|
*
|
||||||
* Alternatively, the contents of this file may be used under the terms of
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
|
@ -39,72 +39,72 @@
|
||||||
define(function(require, exports, module) {
|
define(function(require, exports, module) {
|
||||||
|
|
||||||
var TokenIterator = function(session, initialRow, initialColumn) {
|
var TokenIterator = function(session, initialRow, initialColumn) {
|
||||||
this.$session = session;
|
this.$session = session;
|
||||||
this.$row = initialRow;
|
this.$row = initialRow;
|
||||||
this.$rowTokens = session.getTokens(initialRow, initialRow)[0].tokens;
|
this.$rowTokens = session.getTokens(initialRow, initialRow)[0].tokens;
|
||||||
|
|
||||||
var token = session.getTokenAt(initialRow, initialColumn);
|
var token = session.getTokenAt(initialRow, initialColumn);
|
||||||
this.$tokenIndex = token ? token.index : -1;
|
this.$tokenIndex = token ? token.index : -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
this.stepBackward = function() {
|
this.stepBackward = function() {
|
||||||
this.$tokenIndex -= 1;
|
this.$tokenIndex -= 1;
|
||||||
|
|
||||||
while (this.$tokenIndex < 0) {
|
while (this.$tokenIndex < 0) {
|
||||||
this.$row -= 1;
|
this.$row -= 1;
|
||||||
if (this.$row < 0)
|
if (this.$row < 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
this.$rowTokens = this.$session.getTokens(this.$row, this.$row)[0].tokens;
|
this.$rowTokens = this.$session.getTokens(this.$row, this.$row)[0].tokens;
|
||||||
this.$tokenIndex = this.$rowTokens.length - 1;
|
this.$tokenIndex = this.$rowTokens.length - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.$rowTokens[this.$tokenIndex];
|
return this.$rowTokens[this.$tokenIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
this.stepForward = function() {
|
this.stepForward = function() {
|
||||||
var rowCount = this.$session.getLength();
|
var rowCount = this.$session.getLength();
|
||||||
this.$tokenIndex += 1;
|
this.$tokenIndex += 1;
|
||||||
|
|
||||||
while (this.$tokenIndex >= this.$rowTokens.length) {
|
while (this.$tokenIndex >= this.$rowTokens.length) {
|
||||||
this.$row += 1;
|
this.$row += 1;
|
||||||
if (this.$row >= rowCount)
|
if (this.$row >= rowCount)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
this.$rowTokens = this.$session.getTokens(this.$row, this.$row)[0].tokens;
|
this.$rowTokens = this.$session.getTokens(this.$row, this.$row)[0].tokens;
|
||||||
this.$tokenIndex = 0;
|
this.$tokenIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.$rowTokens[this.$tokenIndex];
|
return this.$rowTokens[this.$tokenIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getCurrentToken = function () {
|
this.getCurrentToken = function () {
|
||||||
return this.$rowTokens[this.$tokenIndex];
|
return this.$rowTokens[this.$tokenIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getCurrentTokenRow = function () {
|
this.getCurrentTokenRow = function () {
|
||||||
return this.$row;
|
return this.$row;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getCurrentTokenColumn = function() {
|
this.getCurrentTokenColumn = function() {
|
||||||
var rowTokens = this.$rowTokens;
|
var rowTokens = this.$rowTokens;
|
||||||
var tokenIndex = this.$tokenIndex;
|
var tokenIndex = this.$tokenIndex;
|
||||||
|
|
||||||
// If a column was cached by EditSession.getTokenAt, then use it
|
// If a column was cached by EditSession.getTokenAt, then use it
|
||||||
var column = rowTokens[tokenIndex].start;
|
var column = rowTokens[tokenIndex].start;
|
||||||
if (column !== undefined)
|
if (column !== undefined)
|
||||||
return column;
|
return column;
|
||||||
|
|
||||||
column = 0;
|
column = 0;
|
||||||
while (tokenIndex > 0) {
|
while (tokenIndex > 0) {
|
||||||
tokenIndex -= 1;
|
tokenIndex -= 1;
|
||||||
column += rowTokens[tokenIndex].value.length;
|
column += rowTokens[tokenIndex].value.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
return column;
|
return column;
|
||||||
}
|
}
|
||||||
|
|
||||||
}).call(TokenIterator.prototype);
|
}).call(TokenIterator.prototype);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue