From 84a0246e2c7c9774af149a0c404548dfbba600fe Mon Sep 17 00:00:00 2001 From: nightwing Date: Mon, 23 Sep 2013 12:14:19 +0400 Subject: [PATCH] highlight matching tag --- lib/ace/edit_session/bracket_match.js | 4 +- lib/ace/mode/folding/xml.js | 75 ++++++++++++++++++++++++++- lib/ace/mode/html.js | 4 ++ lib/ace/mode/xml.js | 3 ++ lib/ace/token_iterator.js | 4 +- 5 files changed, 84 insertions(+), 6 deletions(-) diff --git a/lib/ace/edit_session/bracket_match.js b/lib/ace/edit_session/bracket_match.js index f3923b18..c3de2465 100644 --- a/lib/ace/edit_session/bracket_match.js +++ b/lib/ace/edit_session/bracket_match.js @@ -149,7 +149,7 @@ function BracketMatch() { valueIndex = value.length - 1; } - return null; + return false; }; this.$findClosingBracket = function(bracket, position, type) { @@ -199,7 +199,7 @@ function BracketMatch() { valueIndex = 0; } - return null; + return false; }; } exports.BracketMatch = BracketMatch; diff --git a/lib/ace/mode/folding/xml.js b/lib/ace/mode/folding/xml.js index 3e69ddfa..7c0d949c 100644 --- a/lib/ace/mode/folding/xml.js +++ b/lib/ace/mode/folding/xml.js @@ -164,7 +164,6 @@ oop.inherits(FoldMode, BaseFoldMode); this._pop = function(stack, tag) { while (stack.length) { - var top = stack[stack.length-1]; if (!tag || top.tagName == tag.tagName) { return stack.pop(); @@ -253,6 +252,78 @@ oop.inherits(FoldMode, BaseFoldMode); }; - }).call(FoldMode.prototype); + this.getMatching = function(session, row, column) { + if (row == undefined) + row = session.selection.lead + if (typeof row == "object") { + column = row.column; + row = row.row; + } + + var TAG_NAME = "meta.tag.name"; + + var iterator = new TokenIterator(session, row, column); + var startToken = iterator.getCurrentToken(); + if (!startToken) + return; + if (startToken.type.lastIndexOf(TAG_NAME, 0) == 0) { + startToken = iterator.stepBackward(); + } else + return; + + var isBackward = startToken.value == ""}; + this.getMatching = function(session, row, column) { + return this.foldingRules.getMatching(session, row, column); + } }).call(Mode.prototype); exports.Mode = Mode; diff --git a/lib/ace/token_iterator.js b/lib/ace/token_iterator.js index 74376fb3..cbfd64a9 100644 --- a/lib/ace/token_iterator.js +++ b/lib/ace/token_iterator.js @@ -131,7 +131,7 @@ var TokenIterator = function(session, initialRow, initialColumn) { var tokenIndex = this.$tokenIndex; // If a column was cached by EditSession.getTokenAt, then use it - var column = rowTokens[tokenIndex].start; + var column = rowTokens[tokenIndex] && rowTokens[tokenIndex].start; if (column !== undefined) return column; @@ -141,7 +141,7 @@ var TokenIterator = function(session, initialRow, initialColumn) { column += rowTokens[tokenIndex].value.length; } - return column; + return column; }; }).call(TokenIterator.prototype);