highlight matching tag
This commit is contained in:
parent
528e760dcd
commit
84a0246e2c
5 changed files with 84 additions and 6 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 == "</";
|
||||
var stack = [];
|
||||
var tag;
|
||||
|
||||
if (!isBackward) {
|
||||
while (tag = this._readTagForward(iterator)) {
|
||||
if (tag.selfClosing) {
|
||||
if (!stack.length) {
|
||||
return Range.fromPoints(tag.start, tag.end);
|
||||
} else
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tag.closing) {
|
||||
this._pop(stack, tag);
|
||||
if (!stack.length) {
|
||||
var row = tag.start.row;
|
||||
var col = tag.start.column + 2;
|
||||
return new Range(row, col, row, col + tag.tagName.length)
|
||||
}
|
||||
}
|
||||
else {
|
||||
stack.push(tag)
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
tag = this._readTagForward(iterator);
|
||||
iterator.stepBackward();
|
||||
while (tag = this._readTagBackward(iterator)) {
|
||||
if (tag.selfClosing) {
|
||||
if (!stack.length) {
|
||||
tag.start.column += tag.tagName.length + 2;
|
||||
tag.end.column -= 2;
|
||||
return Range.fromPoints(tag.start, tag.end);
|
||||
} else
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!tag.closing) {
|
||||
this._pop(stack, tag);
|
||||
if (!stack.length) {
|
||||
var row = tag.start.row;
|
||||
var col = tag.start.column + 1;
|
||||
return new Range(row, col, row, col + tag.tagName.length)
|
||||
}
|
||||
}
|
||||
else {
|
||||
stack.push(tag)
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}).call(FoldMode.prototype);
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -69,6 +69,10 @@ oop.inherits(Mode, TextMode);
|
|||
return false;
|
||||
};
|
||||
|
||||
this.getMatching = function(session, row, column) {
|
||||
return this.foldingRules.defaultMode.getMatching(session, row, column);
|
||||
};
|
||||
|
||||
this.getCompletions = function(state, session, pos, prefix) {
|
||||
return this.$completer.getCompletions(state, session, pos, prefix);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -50,6 +50,9 @@ oop.inherits(Mode, TextMode);
|
|||
|
||||
this.blockComment = {start: "<!--", end: "-->"};
|
||||
|
||||
this.getMatching = function(session, row, column) {
|
||||
return this.foldingRules.getMatching(session, row, column);
|
||||
}
|
||||
}).call(Mode.prototype);
|
||||
|
||||
exports.Mode = Mode;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue