From 04a308e00d6477b48c0b76572ca5f2703b74c063 Mon Sep 17 00:00:00 2001 From: nightwing Date: Thu, 14 Mar 2013 16:16:45 +0400 Subject: [PATCH 1/5] make findMatchingBracket faster --- lib/ace/edit_session/bracket_match.js | 30 ++++++++------------------- lib/ace/keyboard/vim/maps/motions.js | 4 ++-- 2 files changed, 11 insertions(+), 23 deletions(-) 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 ++; From 127270a7aa46921cf11471516d492c1c2b8abf47 Mon Sep 17 00:00:00 2001 From: nightwing Date: Fri, 19 Apr 2013 23:04:28 +0400 Subject: [PATCH 2/5] fix mixed folding misses folds on lines drawn before tokenization is finished --- lib/ace/mode/folding/mixed.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/ace/mode/folding/mixed.js b/lib/ace/mode/folding/mixed.js index 40d2cda8..3dd48a7d 100644 --- a/lib/ace/mode/folding/mixed.js +++ b/lib/ace/mode/folding/mixed.js @@ -59,6 +59,8 @@ oop.inherits(FoldMode, BaseFoldMode); }; this.getFoldWidget = function(session, foldStyle, row) { + if (session.bgTokenizer.currentLine < row) + return; return ( this.$tryMode(session.getState(row-1), session, foldStyle, row) || this.$tryMode(session.getState(row), session, foldStyle, row) || From 10a759feb78eaa30094c6a8c8e6db55fde7af518 Mon Sep 17 00:00:00 2001 From: nightwing Date: Thu, 2 May 2013 00:28:37 +0400 Subject: [PATCH 3/5] do not include tag attributes in the fold --- lib/ace/mode/folding/xml.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/ace/mode/folding/xml.js b/lib/ace/mode/folding/xml.js index 5e8e4b9a..3e69ddfa 100644 --- a/lib/ace/mode/folding/xml.js +++ b/lib/ace/mode/folding/xml.js @@ -3,7 +3,7 @@ * * Copyright (c) 2010, Ajax.org B.V. * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright @@ -14,7 +14,7 @@ * * Neither the name of Ajax.org B.V. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -113,7 +113,7 @@ oop.inherits(FoldMode, BaseFoldMode); }; } value += token.value; - if (value.indexOf(">") !== -1) { + if (token.type.slice(-4) === ".end") { var tag = this._parseTag(value); tag.start = start; tag.end = { @@ -195,7 +195,7 @@ oop.inherits(FoldMode, BaseFoldMode); var iterator = new TokenIterator(session, row, firstTag.column); var start = { row: row, - column: firstTag.column + firstTag.tagName.length + 2 + column: firstTag.column + firstTag.match.length }; while (tag = this._readTagForward(iterator)) { if (tag.selfClosing) { @@ -209,8 +209,9 @@ oop.inherits(FoldMode, BaseFoldMode); if (tag.closing) { this._pop(stack, tag); - if (stack.length == 0) + if (!stack.length) return Range.fromPoints(start, tag.start); + } else { stack.push(tag) @@ -236,9 +237,12 @@ oop.inherits(FoldMode, BaseFoldMode); if (!tag.closing) { this._pop(stack, tag); - if (stack.length == 0) { - tag.start.column += tag.tagName.length + 2; - return Range.fromPoints(tag.start, end); + if (!stack.length) { + if (tag.start.row != tag.end.row) { + tag.end = tag.start; + tag.end.column += session.getLine(tag.end.row).length; + } + return Range.fromPoints(tag.end, end); } } else { @@ -246,9 +250,9 @@ oop.inherits(FoldMode, BaseFoldMode); } } } - + }; -}).call(FoldMode.prototype); + }).call(FoldMode.prototype); }); From 528e760dcd00baad6aecc239616c4dd5dfd74b1d Mon Sep 17 00:00:00 2001 From: nightwing Date: Mon, 2 Sep 2013 03:14:17 +0400 Subject: [PATCH 4/5] do not add fold widget for doctype --- lib/ace/mode/xml_highlight_rules.js | 2 +- lib/ace/mode/xml_util.js | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/ace/mode/xml_highlight_rules.js b/lib/ace/mode/xml_highlight_rules.js index dd3d2a28..0968ea4a 100644 --- a/lib/ace/mode/xml_highlight_rules.js +++ b/lib/ace/mode/xml_highlight_rules.js @@ -49,7 +49,7 @@ var XmlHighlightRules = function(normalize) { }, {token : "comment", regex : "<\\!--", next : "comment"}, { - token : ["punctuation.doctype.begin", "meta.tag.doctype"], + token : ["punctuation.doctype.begin", "meta.doctype.tag"], regex : "(<\\!)(DOCTYPE)(?=[\\s])", next : "doctype" }, {include : "tag"}, diff --git a/lib/ace/mode/xml_util.js b/lib/ace/mode/xml_util.js index abae6075..edce54d5 100644 --- a/lib/ace/mode/xml_util.js +++ b/lib/ace/mode/xml_util.js @@ -60,13 +60,12 @@ exports.tag = function(states, name, nextState, tagMap) { regex : "\\s+" }, { //token : "meta.tag", - - token : !tagMap ? "meta.tag.tag-name" : function(value) { + token : tagMap ? function(value) { if (tagMap[value]) return "meta.tag.tag-name." + tagMap[value]; else return "meta.tag.tag-name"; - }, + } : "meta.tag.tag-name", regex : "[-_a-zA-Z0-9:]+", next : name + "_embed_attribute_list" }, { From 84a0246e2c7c9774af149a0c404548dfbba600fe Mon Sep 17 00:00:00 2001 From: nightwing Date: Mon, 23 Sep 2013 12:14:19 +0400 Subject: [PATCH 5/5] 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);