mode-jsx.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. ace.define("ace/mode/doc_comment_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module) {
  2. "use strict";
  3. var oop = require("../lib/oop");
  4. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  5. var DocCommentHighlightRules = function() {
  6. this.$rules = {
  7. "start" : [ {
  8. token : "comment.doc.tag",
  9. regex : "@[\\w\\d_]+" // TODO: fix email addresses
  10. }, {
  11. token : "comment.doc.tag",
  12. regex : "\\bTODO\\b"
  13. }, {
  14. defaultToken : "comment.doc"
  15. }]
  16. };
  17. };
  18. oop.inherits(DocCommentHighlightRules, TextHighlightRules);
  19. DocCommentHighlightRules.getStartRule = function(start) {
  20. return {
  21. token : "comment.doc", // doc comment
  22. regex : "\\/\\*(?=\\*)",
  23. next : start
  24. };
  25. };
  26. DocCommentHighlightRules.getEndRule = function (start) {
  27. return {
  28. token : "comment.doc", // closing comment
  29. regex : "\\*\\/",
  30. next : start
  31. };
  32. };
  33. exports.DocCommentHighlightRules = DocCommentHighlightRules;
  34. });
  35. ace.define("ace/mode/jsx_highlight_rules",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/mode/doc_comment_highlight_rules","ace/mode/text_highlight_rules"], function(require, exports, module) {
  36. var oop = require("../lib/oop");
  37. var lang = require("../lib/lang");
  38. var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
  39. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  40. var JsxHighlightRules = function() {
  41. var keywords = lang.arrayToMap(
  42. ("break|do|instanceof|typeof|case|else|new|var|catch|finally|return|void|continue|for|switch|default|while|function|this|" +
  43. "if|throw|" +
  44. "delete|in|try|" +
  45. "class|extends|super|import|from|into|implements|interface|static|mixin|override|abstract|final|" +
  46. "number|int|string|boolean|variant|" +
  47. "log|assert").split("|")
  48. );
  49. var buildinConstants = lang.arrayToMap(
  50. ("null|true|false|NaN|Infinity|__FILE__|__LINE__|undefined").split("|")
  51. );
  52. var reserved = lang.arrayToMap(
  53. ("debugger|with|" +
  54. "const|export|" +
  55. "let|private|public|yield|protected|" +
  56. "extern|native|as|operator|__fake__|__readonly__").split("|")
  57. );
  58. var identifierRe = "[a-zA-Z_][a-zA-Z0-9_]*\\b";
  59. this.$rules = {
  60. "start" : [
  61. {
  62. token : "comment",
  63. regex : "\\/\\/.*$"
  64. },
  65. DocCommentHighlightRules.getStartRule("doc-start"),
  66. {
  67. token : "comment", // multi line comment
  68. regex : "\\/\\*",
  69. next : "comment"
  70. }, {
  71. token : "string.regexp",
  72. regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
  73. }, {
  74. token : "string", // single line
  75. regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  76. }, {
  77. token : "string", // single line
  78. regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
  79. }, {
  80. token : "constant.numeric", // hex
  81. regex : "0[xX][0-9a-fA-F]+\\b"
  82. }, {
  83. token : "constant.numeric", // float
  84. regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
  85. }, {
  86. token : "constant.language.boolean",
  87. regex : "(?:true|false)\\b"
  88. }, {
  89. token : [
  90. "storage.type",
  91. "text",
  92. "entity.name.function"
  93. ],
  94. regex : "(function)(\\s+)(" + identifierRe + ")"
  95. }, {
  96. token : function(value) {
  97. if (value == "this")
  98. return "variable.language";
  99. else if (value == "function")
  100. return "storage.type";
  101. else if (keywords.hasOwnProperty(value) || reserved.hasOwnProperty(value))
  102. return "keyword";
  103. else if (buildinConstants.hasOwnProperty(value))
  104. return "constant.language";
  105. else if (/^_?[A-Z][a-zA-Z0-9_]*$/.test(value))
  106. return "language.support.class";
  107. else
  108. return "identifier";
  109. },
  110. regex : identifierRe
  111. }, {
  112. token : "keyword.operator",
  113. regex : "!|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|==|=|!=|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
  114. }, {
  115. token : "punctuation.operator",
  116. regex : "\\?|\\:|\\,|\\;|\\."
  117. }, {
  118. token : "paren.lparen",
  119. regex : "[[({<]"
  120. }, {
  121. token : "paren.rparen",
  122. regex : "[\\])}>]"
  123. }, {
  124. token : "text",
  125. regex : "\\s+"
  126. }
  127. ],
  128. "comment" : [
  129. {
  130. token : "comment", // closing comment
  131. regex : ".*?\\*\\/",
  132. next : "start"
  133. }, {
  134. token : "comment", // comment spanning whole line
  135. regex : ".+"
  136. }
  137. ]
  138. };
  139. this.embedRules(DocCommentHighlightRules, "doc-",
  140. [ DocCommentHighlightRules.getEndRule("start") ]);
  141. };
  142. oop.inherits(JsxHighlightRules, TextHighlightRules);
  143. exports.JsxHighlightRules = JsxHighlightRules;
  144. });
  145. ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module) {
  146. "use strict";
  147. var Range = require("../range").Range;
  148. var MatchingBraceOutdent = function() {};
  149. (function() {
  150. this.checkOutdent = function(line, input) {
  151. if (! /^\s+$/.test(line))
  152. return false;
  153. return /^\s*\}/.test(input);
  154. };
  155. this.autoOutdent = function(doc, row) {
  156. var line = doc.getLine(row);
  157. var match = line.match(/^(\s*\})/);
  158. if (!match) return 0;
  159. var column = match[1].length;
  160. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  161. if (!openBracePos || openBracePos.row == row) return 0;
  162. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  163. doc.replace(new Range(row, 0, row, column-1), indent);
  164. };
  165. this.$getIndent = function(line) {
  166. return line.match(/^\s*/)[0];
  167. };
  168. }).call(MatchingBraceOutdent.prototype);
  169. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  170. });
  171. ace.define("ace/mode/behaviour/cstyle",["require","exports","module","ace/lib/oop","ace/mode/behaviour","ace/token_iterator","ace/lib/lang"], function(require, exports, module) {
  172. "use strict";
  173. var oop = require("../../lib/oop");
  174. var Behaviour = require("../behaviour").Behaviour;
  175. var TokenIterator = require("../../token_iterator").TokenIterator;
  176. var lang = require("../../lib/lang");
  177. var SAFE_INSERT_IN_TOKENS =
  178. ["text", "paren.rparen", "punctuation.operator"];
  179. var SAFE_INSERT_BEFORE_TOKENS =
  180. ["text", "paren.rparen", "punctuation.operator", "comment"];
  181. var context;
  182. var contextCache = {}
  183. var initContext = function(editor) {
  184. var id = -1;
  185. if (editor.multiSelect) {
  186. id = editor.selection.id;
  187. if (contextCache.rangeCount != editor.multiSelect.rangeCount)
  188. contextCache = {rangeCount: editor.multiSelect.rangeCount};
  189. }
  190. if (contextCache[id])
  191. return context = contextCache[id];
  192. context = contextCache[id] = {
  193. autoInsertedBrackets: 0,
  194. autoInsertedRow: -1,
  195. autoInsertedLineEnd: "",
  196. maybeInsertedBrackets: 0,
  197. maybeInsertedRow: -1,
  198. maybeInsertedLineStart: "",
  199. maybeInsertedLineEnd: ""
  200. };
  201. };
  202. var CstyleBehaviour = function() {
  203. this.add("braces", "insertion", function(state, action, editor, session, text) {
  204. var cursor = editor.getCursorPosition();
  205. var line = session.doc.getLine(cursor.row);
  206. if (text == '{') {
  207. initContext(editor);
  208. var selection = editor.getSelectionRange();
  209. var selected = session.doc.getTextRange(selection);
  210. if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
  211. return {
  212. text: '{' + selected + '}',
  213. selection: false
  214. };
  215. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  216. if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode) {
  217. CstyleBehaviour.recordAutoInsert(editor, session, "}");
  218. return {
  219. text: '{}',
  220. selection: [1, 1]
  221. };
  222. } else {
  223. CstyleBehaviour.recordMaybeInsert(editor, session, "{");
  224. return {
  225. text: '{',
  226. selection: [1, 1]
  227. };
  228. }
  229. }
  230. } else if (text == '}') {
  231. initContext(editor);
  232. var rightChar = line.substring(cursor.column, cursor.column + 1);
  233. if (rightChar == '}') {
  234. var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
  235. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  236. CstyleBehaviour.popAutoInsertedClosing();
  237. return {
  238. text: '',
  239. selection: [1, 1]
  240. };
  241. }
  242. }
  243. } else if (text == "\n" || text == "\r\n") {
  244. initContext(editor);
  245. var closing = "";
  246. if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
  247. closing = lang.stringRepeat("}", context.maybeInsertedBrackets);
  248. CstyleBehaviour.clearMaybeInsertedClosing();
  249. }
  250. var rightChar = line.substring(cursor.column, cursor.column + 1);
  251. if (rightChar === '}') {
  252. var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column+1}, '}');
  253. if (!openBracePos)
  254. return null;
  255. var next_indent = this.$getIndent(session.getLine(openBracePos.row));
  256. } else if (closing) {
  257. var next_indent = this.$getIndent(line);
  258. } else {
  259. CstyleBehaviour.clearMaybeInsertedClosing();
  260. return;
  261. }
  262. var indent = next_indent + session.getTabString();
  263. return {
  264. text: '\n' + indent + '\n' + next_indent + closing,
  265. selection: [1, indent.length, 1, indent.length]
  266. };
  267. } else {
  268. CstyleBehaviour.clearMaybeInsertedClosing();
  269. }
  270. });
  271. this.add("braces", "deletion", function(state, action, editor, session, range) {
  272. var selected = session.doc.getTextRange(range);
  273. if (!range.isMultiLine() && selected == '{') {
  274. initContext(editor);
  275. var line = session.doc.getLine(range.start.row);
  276. var rightChar = line.substring(range.end.column, range.end.column + 1);
  277. if (rightChar == '}') {
  278. range.end.column++;
  279. return range;
  280. } else {
  281. context.maybeInsertedBrackets--;
  282. }
  283. }
  284. });
  285. this.add("parens", "insertion", function(state, action, editor, session, text) {
  286. if (text == '(') {
  287. initContext(editor);
  288. var selection = editor.getSelectionRange();
  289. var selected = session.doc.getTextRange(selection);
  290. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  291. return {
  292. text: '(' + selected + ')',
  293. selection: false
  294. };
  295. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  296. CstyleBehaviour.recordAutoInsert(editor, session, ")");
  297. return {
  298. text: '()',
  299. selection: [1, 1]
  300. };
  301. }
  302. } else if (text == ')') {
  303. initContext(editor);
  304. var cursor = editor.getCursorPosition();
  305. var line = session.doc.getLine(cursor.row);
  306. var rightChar = line.substring(cursor.column, cursor.column + 1);
  307. if (rightChar == ')') {
  308. var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
  309. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  310. CstyleBehaviour.popAutoInsertedClosing();
  311. return {
  312. text: '',
  313. selection: [1, 1]
  314. };
  315. }
  316. }
  317. }
  318. });
  319. this.add("parens", "deletion", function(state, action, editor, session, range) {
  320. var selected = session.doc.getTextRange(range);
  321. if (!range.isMultiLine() && selected == '(') {
  322. initContext(editor);
  323. var line = session.doc.getLine(range.start.row);
  324. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  325. if (rightChar == ')') {
  326. range.end.column++;
  327. return range;
  328. }
  329. }
  330. });
  331. this.add("brackets", "insertion", function(state, action, editor, session, text) {
  332. if (text == '[') {
  333. initContext(editor);
  334. var selection = editor.getSelectionRange();
  335. var selected = session.doc.getTextRange(selection);
  336. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  337. return {
  338. text: '[' + selected + ']',
  339. selection: false
  340. };
  341. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  342. CstyleBehaviour.recordAutoInsert(editor, session, "]");
  343. return {
  344. text: '[]',
  345. selection: [1, 1]
  346. };
  347. }
  348. } else if (text == ']') {
  349. initContext(editor);
  350. var cursor = editor.getCursorPosition();
  351. var line = session.doc.getLine(cursor.row);
  352. var rightChar = line.substring(cursor.column, cursor.column + 1);
  353. if (rightChar == ']') {
  354. var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
  355. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  356. CstyleBehaviour.popAutoInsertedClosing();
  357. return {
  358. text: '',
  359. selection: [1, 1]
  360. };
  361. }
  362. }
  363. }
  364. });
  365. this.add("brackets", "deletion", function(state, action, editor, session, range) {
  366. var selected = session.doc.getTextRange(range);
  367. if (!range.isMultiLine() && selected == '[') {
  368. initContext(editor);
  369. var line = session.doc.getLine(range.start.row);
  370. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  371. if (rightChar == ']') {
  372. range.end.column++;
  373. return range;
  374. }
  375. }
  376. });
  377. this.add("string_dquotes", "insertion", function(state, action, editor, session, text) {
  378. if (text == '"' || text == "'") {
  379. initContext(editor);
  380. var quote = text;
  381. var selection = editor.getSelectionRange();
  382. var selected = session.doc.getTextRange(selection);
  383. if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
  384. return {
  385. text: quote + selected + quote,
  386. selection: false
  387. };
  388. } else {
  389. var cursor = editor.getCursorPosition();
  390. var line = session.doc.getLine(cursor.row);
  391. var leftChar = line.substring(cursor.column-1, cursor.column);
  392. if (leftChar == '\\') {
  393. return null;
  394. }
  395. var tokens = session.getTokens(selection.start.row);
  396. var col = 0, token;
  397. var quotepos = -1; // Track whether we're inside an open quote.
  398. for (var x = 0; x < tokens.length; x++) {
  399. token = tokens[x];
  400. if (token.type == "string") {
  401. quotepos = -1;
  402. } else if (quotepos < 0) {
  403. quotepos = token.value.indexOf(quote);
  404. }
  405. if ((token.value.length + col) > selection.start.column) {
  406. break;
  407. }
  408. col += tokens[x].value.length;
  409. }
  410. if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf(quote) === token.value.length-1)))) {
  411. if (!CstyleBehaviour.isSaneInsertion(editor, session))
  412. return;
  413. return {
  414. text: quote + quote,
  415. selection: [1,1]
  416. };
  417. } else if (token && token.type === "string") {
  418. var rightChar = line.substring(cursor.column, cursor.column + 1);
  419. if (rightChar == quote) {
  420. return {
  421. text: '',
  422. selection: [1, 1]
  423. };
  424. }
  425. }
  426. }
  427. }
  428. });
  429. this.add("string_dquotes", "deletion", function(state, action, editor, session, range) {
  430. var selected = session.doc.getTextRange(range);
  431. if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
  432. initContext(editor);
  433. var line = session.doc.getLine(range.start.row);
  434. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  435. if (rightChar == selected) {
  436. range.end.column++;
  437. return range;
  438. }
  439. }
  440. });
  441. };
  442. CstyleBehaviour.isSaneInsertion = function(editor, session) {
  443. var cursor = editor.getCursorPosition();
  444. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  445. if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
  446. var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
  447. if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
  448. return false;
  449. }
  450. iterator.stepForward();
  451. return iterator.getCurrentTokenRow() !== cursor.row ||
  452. this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
  453. };
  454. CstyleBehaviour.$matchTokenType = function(token, types) {
  455. return types.indexOf(token.type || token) > -1;
  456. };
  457. CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
  458. var cursor = editor.getCursorPosition();
  459. var line = session.doc.getLine(cursor.row);
  460. if (!this.isAutoInsertedClosing(cursor, line, context.autoInsertedLineEnd[0]))
  461. context.autoInsertedBrackets = 0;
  462. context.autoInsertedRow = cursor.row;
  463. context.autoInsertedLineEnd = bracket + line.substr(cursor.column);
  464. context.autoInsertedBrackets++;
  465. };
  466. CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
  467. var cursor = editor.getCursorPosition();
  468. var line = session.doc.getLine(cursor.row);
  469. if (!this.isMaybeInsertedClosing(cursor, line))
  470. context.maybeInsertedBrackets = 0;
  471. context.maybeInsertedRow = cursor.row;
  472. context.maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
  473. context.maybeInsertedLineEnd = line.substr(cursor.column);
  474. context.maybeInsertedBrackets++;
  475. };
  476. CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
  477. return context.autoInsertedBrackets > 0 &&
  478. cursor.row === context.autoInsertedRow &&
  479. bracket === context.autoInsertedLineEnd[0] &&
  480. line.substr(cursor.column) === context.autoInsertedLineEnd;
  481. };
  482. CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
  483. return context.maybeInsertedBrackets > 0 &&
  484. cursor.row === context.maybeInsertedRow &&
  485. line.substr(cursor.column) === context.maybeInsertedLineEnd &&
  486. line.substr(0, cursor.column) == context.maybeInsertedLineStart;
  487. };
  488. CstyleBehaviour.popAutoInsertedClosing = function() {
  489. context.autoInsertedLineEnd = context.autoInsertedLineEnd.substr(1);
  490. context.autoInsertedBrackets--;
  491. };
  492. CstyleBehaviour.clearMaybeInsertedClosing = function() {
  493. if (context) {
  494. context.maybeInsertedBrackets = 0;
  495. context.maybeInsertedRow = -1;
  496. }
  497. };
  498. oop.inherits(CstyleBehaviour, Behaviour);
  499. exports.CstyleBehaviour = CstyleBehaviour;
  500. });
  501. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
  502. "use strict";
  503. var oop = require("../../lib/oop");
  504. var Range = require("../../range").Range;
  505. var BaseFoldMode = require("./fold_mode").FoldMode;
  506. var FoldMode = exports.FoldMode = function(commentRegex) {
  507. if (commentRegex) {
  508. this.foldingStartMarker = new RegExp(
  509. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  510. );
  511. this.foldingStopMarker = new RegExp(
  512. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  513. );
  514. }
  515. };
  516. oop.inherits(FoldMode, BaseFoldMode);
  517. (function() {
  518. this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
  519. this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
  520. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  521. var line = session.getLine(row);
  522. var match = line.match(this.foldingStartMarker);
  523. if (match) {
  524. var i = match.index;
  525. if (match[1])
  526. return this.openingBracketBlock(session, match[1], row, i);
  527. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  528. if (range && !range.isMultiLine()) {
  529. if (forceMultiline) {
  530. range = this.getSectionRange(session, row);
  531. } else if (foldStyle != "all")
  532. range = null;
  533. }
  534. return range;
  535. }
  536. if (foldStyle === "markbegin")
  537. return;
  538. var match = line.match(this.foldingStopMarker);
  539. if (match) {
  540. var i = match.index + match[0].length;
  541. if (match[1])
  542. return this.closingBracketBlock(session, match[1], row, i);
  543. return session.getCommentFoldRange(row, i, -1);
  544. }
  545. };
  546. this.getSectionRange = function(session, row) {
  547. var line = session.getLine(row);
  548. var startIndent = line.search(/\S/);
  549. var startRow = row;
  550. var startColumn = line.length;
  551. row = row + 1;
  552. var endRow = row;
  553. var maxRow = session.getLength();
  554. while (++row < maxRow) {
  555. line = session.getLine(row);
  556. var indent = line.search(/\S/);
  557. if (indent === -1)
  558. continue;
  559. if (startIndent > indent)
  560. break;
  561. var subRange = this.getFoldWidgetRange(session, "all", row);
  562. if (subRange) {
  563. if (subRange.start.row <= startRow) {
  564. break;
  565. } else if (subRange.isMultiLine()) {
  566. row = subRange.end.row;
  567. } else if (startIndent == indent) {
  568. break;
  569. }
  570. }
  571. endRow = row;
  572. }
  573. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  574. };
  575. }).call(FoldMode.prototype);
  576. });
  577. ace.define("ace/mode/jsx",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/jsx_highlight_rules","ace/mode/matching_brace_outdent","ace/mode/behaviour/cstyle","ace/mode/folding/cstyle"], function(require, exports, module) {
  578. "use strict";
  579. var oop = require("../lib/oop");
  580. var TextMode = require("./text").Mode;
  581. var JsxHighlightRules = require("./jsx_highlight_rules").JsxHighlightRules;
  582. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  583. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  584. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  585. function Mode() {
  586. this.HighlightRules = JsxHighlightRules;
  587. this.$outdent = new MatchingBraceOutdent();
  588. this.$behaviour = new CstyleBehaviour();
  589. this.foldingRules = new CStyleFoldMode();
  590. }
  591. oop.inherits(Mode, TextMode);
  592. (function() {
  593. this.lineCommentStart = "//";
  594. this.blockComment = {start: "/*", end: "*/"};
  595. this.getNextLineIndent = function(state, line, tab) {
  596. var indent = this.$getIndent(line);
  597. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  598. var tokens = tokenizedLine.tokens;
  599. if (tokens.length && tokens[tokens.length-1].type == "comment") {
  600. return indent;
  601. }
  602. if (state == "start") {
  603. var match = line.match(/^.*[\{\(\[]\s*$/);
  604. if (match) {
  605. indent += tab;
  606. }
  607. }
  608. return indent;
  609. };
  610. this.checkOutdent = function(state, line, input) {
  611. return this.$outdent.checkOutdent(line, input);
  612. };
  613. this.autoOutdent = function(state, doc, row) {
  614. this.$outdent.autoOutdent(doc, row);
  615. };
  616. this.$id = "ace/mode/jsx";
  617. }).call(Mode.prototype);
  618. exports.Mode = Mode;
  619. });