|
|
@@ -5,6 +5,8 @@ var oop = require("../lib/oop");
|
|
|
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
|
|
|
|
|
|
var XmlHighlightRules = function(normalize) {
|
|
|
+ var tagRegex = "[_:a-zA-Z\xc0-\uffff][-_:.a-zA-Z0-9\xc0-\uffff]*";
|
|
|
+
|
|
|
this.$rules = {
|
|
|
start : [
|
|
|
{token : "string.cdata.xml", regex : "<\\!\\[CDATA\\[", next : "cdata"},
|
|
|
@@ -14,7 +16,7 @@ var XmlHighlightRules = function(normalize) {
|
|
|
},
|
|
|
{
|
|
|
token : ["punctuation.instruction.xml", "keyword.instruction.xml"],
|
|
|
- regex : "(<\\?)([-_a-zA-Z0-9]+)", next : "processing_instruction",
|
|
|
+ regex : "(<\\?)(" + tagRegex + ")", next : "processing_instruction",
|
|
|
},
|
|
|
{token : "comment.xml", regex : "<\\!--", next : "comment"},
|
|
|
{
|
|
|
@@ -30,7 +32,7 @@ var XmlHighlightRules = function(normalize) {
|
|
|
|
|
|
xml_decl : [{
|
|
|
token : "entity.other.attribute-name.decl-attribute-name.xml",
|
|
|
- regex : "(?:[-_a-zA-Z0-9]+:)?[-_a-zA-Z0-9]+"
|
|
|
+ regex : "(?:" + tagRegex + ":)?" + tagRegex + ""
|
|
|
}, {
|
|
|
token : "keyword.operator.decl-attribute-equals.xml",
|
|
|
regex : "="
|
|
|
@@ -66,7 +68,7 @@ var XmlHighlightRules = function(normalize) {
|
|
|
next: "pop"
|
|
|
}, {
|
|
|
token : ["punctuation.markup-decl.xml", "keyword.markup-decl.xml"],
|
|
|
- regex : "(<\\!)([-_a-zA-Z0-9]+)",
|
|
|
+ regex : "(<\\!)(" + tagRegex + ")",
|
|
|
push : [{
|
|
|
token : "text",
|
|
|
regex : "\\s+"
|
|
|
@@ -102,7 +104,7 @@ var XmlHighlightRules = function(normalize) {
|
|
|
|
|
|
tag : [{
|
|
|
token : ["meta.tag.punctuation.tag-open.xml", "meta.tag.punctuation.end-tag-open.xml", "meta.tag.tag-name.xml"],
|
|
|
- regex : "(?:(<)|(</))((?:[-_a-zA-Z0-9]+:)?[-_a-zA-Z0-9]+)",
|
|
|
+ regex : "(?:(<)|(</))((?:" + tagRegex + ":)?" + tagRegex + ")",
|
|
|
next: [
|
|
|
{include : "attributes"},
|
|
|
{token : "meta.tag.punctuation.tag-close.xml", regex : "/?>", next : "start"}
|
|
|
@@ -133,7 +135,7 @@ var XmlHighlightRules = function(normalize) {
|
|
|
|
|
|
attributes: [{
|
|
|
token : "entity.other.attribute-name.xml",
|
|
|
- regex : "(?:[-_a-zA-Z0-9]+:)?[-_a-zA-Z0-9]+"
|
|
|
+ regex : "(?:" + tagRegex + ":)?" + tagRegex + ""
|
|
|
}, {
|
|
|
token : "keyword.operator.attribute-equals.xml",
|
|
|
regex : "="
|
|
|
@@ -326,6 +328,8 @@ var XmlBehaviour = function () {
|
|
|
var token = iterator.getCurrentToken();
|
|
|
|
|
|
if (token && token.type.indexOf("tag-close") !== -1) {
|
|
|
+ if (token.value == "/>")
|
|
|
+ return;
|
|
|
while (token && token.type.indexOf("tag-name") === -1) {
|
|
|
token = iterator.stepBackward();
|
|
|
}
|
|
|
@@ -550,6 +554,8 @@ function is(token, type) {
|
|
|
row: row,
|
|
|
column: firstTag.start.column + firstTag.tagName.length + 2
|
|
|
};
|
|
|
+ if (firstTag.start.row == firstTag.end.row)
|
|
|
+ start.column = firstTag.end.column;
|
|
|
while (tag = this._readTagForward(iterator)) {
|
|
|
if (tag.selfClosing) {
|
|
|
if (!stack.length) {
|
|
|
@@ -591,6 +597,8 @@ function is(token, type) {
|
|
|
this._pop(stack, tag);
|
|
|
if (stack.length == 0) {
|
|
|
tag.start.column += tag.tagName.length + 2;
|
|
|
+ if (tag.start.row == tag.end.row && tag.start.column < tag.end.column)
|
|
|
+ tag.start.column = tag.end.column;
|
|
|
return Range.fromPoints(tag.start, end);
|
|
|
}
|
|
|
}
|
|
|
@@ -606,7 +614,7 @@ function is(token, type) {
|
|
|
|
|
|
});
|
|
|
|
|
|
-ace.define("ace/mode/xml",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/mode/text","ace/mode/xml_highlight_rules","ace/mode/behaviour/xml","ace/mode/folding/xml"], function(require, exports, module) {
|
|
|
+ace.define("ace/mode/xml",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/mode/text","ace/mode/xml_highlight_rules","ace/mode/behaviour/xml","ace/mode/folding/xml","ace/worker/worker_client"], function(require, exports, module) {
|
|
|
"use strict";
|
|
|
|
|
|
var oop = require("../lib/oop");
|
|
|
@@ -615,11 +623,12 @@ var TextMode = require("./text").Mode;
|
|
|
var XmlHighlightRules = require("./xml_highlight_rules").XmlHighlightRules;
|
|
|
var XmlBehaviour = require("./behaviour/xml").XmlBehaviour;
|
|
|
var XmlFoldMode = require("./folding/xml").FoldMode;
|
|
|
+var WorkerClient = require("../worker/worker_client").WorkerClient;
|
|
|
|
|
|
var Mode = function() {
|
|
|
- this.HighlightRules = XmlHighlightRules;
|
|
|
- this.$behaviour = new XmlBehaviour();
|
|
|
- this.foldingRules = new XmlFoldMode();
|
|
|
+ this.HighlightRules = XmlHighlightRules;
|
|
|
+ this.$behaviour = new XmlBehaviour();
|
|
|
+ this.foldingRules = new XmlFoldMode();
|
|
|
};
|
|
|
|
|
|
oop.inherits(Mode, TextMode);
|
|
|
@@ -630,6 +639,21 @@ oop.inherits(Mode, TextMode);
|
|
|
|
|
|
this.blockComment = {start: "<!--", end: "-->"};
|
|
|
|
|
|
+ this.createWorker = function(session) {
|
|
|
+ var worker = new WorkerClient(["ace"], "ace/mode/xml_worker", "Worker");
|
|
|
+ worker.attachToDocument(session.getDocument());
|
|
|
+
|
|
|
+ worker.on("error", function(e) {
|
|
|
+ session.setAnnotations(e.data);
|
|
|
+ });
|
|
|
+
|
|
|
+ worker.on("terminate", function() {
|
|
|
+ session.clearAnnotations();
|
|
|
+ });
|
|
|
+
|
|
|
+ return worker;
|
|
|
+ };
|
|
|
+
|
|
|
this.$id = "ace/mode/xml";
|
|
|
}).call(Mode.prototype);
|
|
|
|
|
|
@@ -814,7 +838,7 @@ var JavaScriptHighlightRules = function(options) {
|
|
|
regex : /(\.)(s(?:h(?:ift|ow(?:Mod(?:elessDialog|alDialog)|Help))|croll(?:X|By(?:Pages|Lines)?|Y|To)?|t(?:op|rike)|i(?:n|zeToContent|debar|gnText)|ort|u(?:p|b(?:str(?:ing)?)?)|pli(?:ce|t)|e(?:nd|t(?:Re(?:sizable|questHeader)|M(?:i(?:nutes|lliseconds)|onth)|Seconds|Ho(?:tKeys|urs)|Year|Cursor|Time(?:out)?|Interval|ZOptions|Date|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(?:ome|andleEvent)|navigate|c(?:har(?:CodeAt|At)|o(?:s|n(?:cat|textual|firm)|mpile)|eil|lear(?:Timeout|Interval)?|a(?:ptureEvents|ll)|reate(?:StyleSheet|Popup|EventObject))|t(?:o(?:GMTString|S(?:tring|ource)|U(?:TCString|pperCase)|Lo(?:caleString|werCase))|est|a(?:n|int(?:Enabled)?))|i(?:s(?:NaN|Finite)|ndexOf|talics)|d(?:isableExternalCapture|ump|etachEvent)|u(?:n(?:shift|taint|escape|watch)|pdateCommands)|j(?:oin|avaEnabled)|p(?:o(?:p|w)|ush|lugins.refresh|a(?:ddings|rse(?:Int|Float)?)|r(?:int|ompt|eference))|e(?:scape|nableExternalCapture|val|lementFromPoint|x(?:p|ec(?:Script|Command)?))|valueOf|UTC|queryCommand(?:State|Indeterm|Enabled|Value)|f(?:i(?:nd|le(?:ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(?:nt(?:size|color)|rward)|loor|romCharCode)|watch|l(?:ink|o(?:ad|g)|astIndexOf)|a(?:sin|nchor|cos|t(?:tachEvent|ob|an(?:2)?)|pply|lert|b(?:s|ort))|r(?:ou(?:nd|teEvents)|e(?:size(?:By|To)|calc|turnValue|place|verse|l(?:oad|ease(?:Capture|Events)))|andom)|g(?:o|et(?:ResponseHeader|M(?:i(?:nutes|lliseconds)|onth)|Se(?:conds|lection)|Hours|Year|Time(?:zoneOffset)?|Da(?:y|te)|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Da(?:y|te)|FullYear)|FullYear|A(?:ttention|llResponseHeaders)))|m(?:in|ove(?:B(?:y|elow)|To(?:Absolute)?|Above)|ergeAttributes|a(?:tch|rgins|x))|b(?:toa|ig|o(?:ld|rderWidths)|link|ack))\b(?=\()/
|
|
|
}, {
|
|
|
token : ["punctuation.operator", "support.function.dom"],
|
|
|
- regex : /(\.)(s(?:ub(?:stringData|mit)|plitText|e(?:t(?:NamedItem|Attribute(?:Node)?)|lect))|has(?:ChildNodes|Feature)|namedItem|c(?:l(?:ick|o(?:se|neNode))|reate(?:C(?:omment|DATASection|aption)|T(?:Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(?:ntityReference|lement)|Attribute))|tabIndex|i(?:nsert(?:Row|Before|Cell|Data)|tem)|open|delete(?:Row|C(?:ell|aption)|T(?:Head|Foot)|Data)|focus|write(?:ln)?|a(?:dd|ppend(?:Child|Data))|re(?:set|place(?:Child|Data)|move(?:NamedItem|Child|Attribute(?:Node)?)?)|get(?:NamedItem|Element(?:sBy(?:Name|TagName)|ById)|Attribute(?:Node)?)|blur)\b(?=\()/
|
|
|
+ regex : /(\.)(s(?:ub(?:stringData|mit)|plitText|e(?:t(?:NamedItem|Attribute(?:Node)?)|lect))|has(?:ChildNodes|Feature)|namedItem|c(?:l(?:ick|o(?:se|neNode))|reate(?:C(?:omment|DATASection|aption)|T(?:Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(?:ntityReference|lement)|Attribute))|tabIndex|i(?:nsert(?:Row|Before|Cell|Data)|tem)|open|delete(?:Row|C(?:ell|aption)|T(?:Head|Foot)|Data)|focus|write(?:ln)?|a(?:dd|ppend(?:Child|Data))|re(?:set|place(?:Child|Data)|move(?:NamedItem|Child|Attribute(?:Node)?)?)|get(?:NamedItem|Element(?:sBy(?:Name|TagName|ClassName)|ById)|Attribute(?:Node)?)|blur)\b(?=\()/
|
|
|
}, {
|
|
|
token : ["punctuation.operator", "support.constant"],
|
|
|
regex : /(\.)(s(?:ystemLanguage|cr(?:ipts|ollbars|een(?:X|Y|Top|Left))|t(?:yle(?:Sheets)?|atus(?:Text|bar)?)|ibling(?:Below|Above)|ource|uffixes|e(?:curity(?:Policy)?|l(?:ection|f)))|h(?:istory|ost(?:name)?|as(?:h|Focus))|y|X(?:MLDocument|SLDocument)|n(?:ext|ame(?:space(?:s|URI)|Prop))|M(?:IN_VALUE|AX_VALUE)|c(?:haracterSet|o(?:n(?:structor|trollers)|okieEnabled|lorDepth|mp(?:onents|lete))|urrent|puClass|l(?:i(?:p(?:boardData)?|entInformation)|osed|asses)|alle(?:e|r)|rypto)|t(?:o(?:olbar|p)|ext(?:Transform|Indent|Decoration|Align)|ags)|SQRT(?:1_2|2)|i(?:n(?:ner(?:Height|Width)|put)|ds|gnoreCase)|zIndex|o(?:scpu|n(?:readystatechange|Line)|uter(?:Height|Width)|p(?:sProfile|ener)|ffscreenBuffering)|NEGATIVE_INFINITY|d(?:i(?:splay|alog(?:Height|Top|Width|Left|Arguments)|rectories)|e(?:scription|fault(?:Status|Ch(?:ecked|arset)|View)))|u(?:ser(?:Profile|Language|Agent)|n(?:iqueID|defined)|pdateInterval)|_content|p(?:ixelDepth|ort|ersonalbar|kcs11|l(?:ugins|atform)|a(?:thname|dding(?:Right|Bottom|Top|Left)|rent(?:Window|Layer)?|ge(?:X(?:Offset)?|Y(?:Offset)?))|r(?:o(?:to(?:col|type)|duct(?:Sub)?|mpter)|e(?:vious|fix)))|e(?:n(?:coding|abledPlugin)|x(?:ternal|pando)|mbeds)|v(?:isibility|endor(?:Sub)?|Linkcolor)|URLUnencoded|P(?:I|OSITIVE_INFINITY)|f(?:ilename|o(?:nt(?:Size|Family|Weight)|rmName)|rame(?:s|Element)|gColor)|E|whiteSpace|l(?:i(?:stStyleType|n(?:eHeight|kColor))|o(?:ca(?:tion(?:bar)?|lName)|wsrc)|e(?:ngth|ft(?:Context)?)|a(?:st(?:M(?:odified|atch)|Index|Paren)|yer(?:s|X)|nguage))|a(?:pp(?:MinorVersion|Name|Co(?:deName|re)|Version)|vail(?:Height|Top|Width|Left)|ll|r(?:ity|guments)|Linkcolor|bove)|r(?:ight(?:Context)?|e(?:sponse(?:XML|Text)|adyState))|global|x|m(?:imeTypes|ultiline|enubar|argin(?:Right|Bottom|Top|Left))|L(?:N(?:10|2)|OG(?:10E|2E))|b(?:o(?:ttom|rder(?:Width|RightWidth|BottomWidth|Style|Color|TopWidth|LeftWidth))|ufferDepth|elow|ackground(?:Color|Image)))\b/
|
|
|
@@ -1113,6 +1137,19 @@ var initContext = function(editor) {
|
|
|
};
|
|
|
};
|
|
|
|
|
|
+var getWrapped = function(selection, selected, opening, closing) {
|
|
|
+ var rowDiff = selection.end.row - selection.start.row;
|
|
|
+ return {
|
|
|
+ text: opening + selected + closing,
|
|
|
+ selection: [
|
|
|
+ 0,
|
|
|
+ selection.start.column + 1,
|
|
|
+ rowDiff,
|
|
|
+ selection.end.column + (rowDiff ? 0 : 1)
|
|
|
+ ]
|
|
|
+ };
|
|
|
+};
|
|
|
+
|
|
|
var CstyleBehaviour = function() {
|
|
|
this.add("braces", "insertion", function(state, action, editor, session, text) {
|
|
|
var cursor = editor.getCursorPosition();
|
|
|
@@ -1122,10 +1159,7 @@ var CstyleBehaviour = function() {
|
|
|
var selection = editor.getSelectionRange();
|
|
|
var selected = session.doc.getTextRange(selection);
|
|
|
if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
|
|
|
- return {
|
|
|
- text: '{' + selected + '}',
|
|
|
- selection: false
|
|
|
- };
|
|
|
+ return getWrapped(selection, selected, '{', '}');
|
|
|
} else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
|
|
|
if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode) {
|
|
|
CstyleBehaviour.recordAutoInsert(editor, session, "}");
|
|
|
@@ -1205,10 +1239,7 @@ var CstyleBehaviour = function() {
|
|
|
var selection = editor.getSelectionRange();
|
|
|
var selected = session.doc.getTextRange(selection);
|
|
|
if (selected !== "" && editor.getWrapBehavioursEnabled()) {
|
|
|
- return {
|
|
|
- text: '(' + selected + ')',
|
|
|
- selection: false
|
|
|
- };
|
|
|
+ return getWrapped(selection, selected, '(', ')');
|
|
|
} else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
|
|
|
CstyleBehaviour.recordAutoInsert(editor, session, ")");
|
|
|
return {
|
|
|
@@ -1253,10 +1284,7 @@ var CstyleBehaviour = function() {
|
|
|
var selection = editor.getSelectionRange();
|
|
|
var selected = session.doc.getTextRange(selection);
|
|
|
if (selected !== "" && editor.getWrapBehavioursEnabled()) {
|
|
|
- return {
|
|
|
- text: '[' + selected + ']',
|
|
|
- selection: false
|
|
|
- };
|
|
|
+ return getWrapped(selection, selected, '[', ']');
|
|
|
} else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
|
|
|
CstyleBehaviour.recordAutoInsert(editor, session, "]");
|
|
|
return {
|
|
|
@@ -1302,11 +1330,8 @@ var CstyleBehaviour = function() {
|
|
|
var selection = editor.getSelectionRange();
|
|
|
var selected = session.doc.getTextRange(selection);
|
|
|
if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
|
|
|
- return {
|
|
|
- text: quote + selected + quote,
|
|
|
- selection: false
|
|
|
- };
|
|
|
- } else {
|
|
|
+ return getWrapped(selection, selected, quote, quote);
|
|
|
+ } else if (!selected) {
|
|
|
var cursor = editor.getCursorPosition();
|
|
|
var line = session.doc.getLine(cursor.row);
|
|
|
var leftChar = line.substring(cursor.column-1, cursor.column);
|
|
|
@@ -1317,8 +1342,8 @@ var CstyleBehaviour = function() {
|
|
|
if (leftChar == "\\" && token && /escape/.test(token.type))
|
|
|
return null;
|
|
|
|
|
|
- var stringBefore = token && /string/.test(token.type);
|
|
|
- var stringAfter = !rightToken || /string/.test(rightToken.type);
|
|
|
+ var stringBefore = token && /string|escape/.test(token.type);
|
|
|
+ var stringAfter = !rightToken || /string|escape/.test(rightToken.type);
|
|
|
|
|
|
var pair;
|
|
|
if (rightChar == quote) {
|
|
|
@@ -1327,7 +1352,7 @@ var CstyleBehaviour = function() {
|
|
|
if (stringBefore && !stringAfter)
|
|
|
return null; // wrap string with different quote
|
|
|
if (stringBefore && stringAfter)
|
|
|
- return null; // do not pair quotes inside strings
|
|
|
+ return null; // do not pair quotes inside strings
|
|
|
var wordRe = session.$mode.tokenRe;
|
|
|
wordRe.lastIndex = 0;
|
|
|
var isWordBefore = wordRe.test(leftChar);
|
|
|
@@ -1459,7 +1484,7 @@ oop.inherits(FoldMode, BaseFoldMode);
|
|
|
this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
|
|
|
this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
|
|
|
this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
|
|
|
- this.startRegionRe = /^\s*(\/\*|\/\/)#region\b/;
|
|
|
+ this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
|
|
|
this._getFoldWidgetBase = this.getFoldWidget;
|
|
|
this.getFoldWidget = function(session, foldStyle, row) {
|
|
|
var line = session.getLine(row);
|
|
|
@@ -1547,13 +1572,12 @@ oop.inherits(FoldMode, BaseFoldMode);
|
|
|
|
|
|
return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
|
|
|
};
|
|
|
-
|
|
|
this.getCommentRegionBlock = function(session, line, row) {
|
|
|
var startColumn = line.search(/\s*$/);
|
|
|
var maxRow = session.getLength();
|
|
|
var startRow = row;
|
|
|
|
|
|
- var re = /^\s*(?:\/\*|\/\/)#(end)?region\b/;
|
|
|
+ var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
|
|
|
var depth = 1;
|
|
|
while (++row < maxRow) {
|
|
|
line = session.getLine(row);
|
|
|
@@ -1645,7 +1669,7 @@ oop.inherits(Mode, TextMode);
|
|
|
var worker = new WorkerClient(["ace"], "ace/mode/javascript_worker", "JavaScriptWorker");
|
|
|
worker.attachToDocument(session.getDocument());
|
|
|
|
|
|
- worker.on("jslint", function(results) {
|
|
|
+ worker.on("annotate", function(results) {
|
|
|
session.setAnnotations(results.data);
|
|
|
});
|
|
|
|