mode-json-uncompressed.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3. *
  4. * The contents of this file are subject to the Mozilla Public License Version
  5. * 1.1 (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. * http://www.mozilla.org/MPL/
  8. *
  9. * Software distributed under the License is distributed on an "AS IS" basis,
  10. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. * for the specific language governing rights and limitations under the
  12. * License.
  13. *
  14. * The Original Code is Ajax.org Code Editor (ACE).
  15. *
  16. * The Initial Developer of the Original Code is
  17. * Ajax.org B.V.
  18. * Portions created by the Initial Developer are Copyright (C) 2010
  19. * the Initial Developer. All Rights Reserved.
  20. *
  21. * Contributor(s):
  22. * Fabian Jakobs <fabian AT ajax DOT org>
  23. *
  24. * Alternatively, the contents of this file may be used under the terms of
  25. * either the GNU General Public License Version 2 or later (the "GPL"), or
  26. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27. * in which case the provisions of the GPL or the LGPL are applicable instead
  28. * of those above. If you wish to allow use of your version of this file only
  29. * under the terms of either the GPL or the LGPL, and not to allow others to
  30. * use your version of this file under the terms of the MPL, indicate your
  31. * decision by deleting the provisions above and replace them with the notice
  32. * and other provisions required by the GPL or the LGPL. If you do not delete
  33. * the provisions above, a recipient may use your version of this file under
  34. * the terms of any one of the MPL, the GPL or the LGPL.
  35. *
  36. * ***** END LICENSE BLOCK ***** */
  37. define('ace/mode/json', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/json_highlight_rules', 'ace/mode/matching_brace_outdent', 'ace/mode/behaviour/cstyle', 'ace/mode/folding/cstyle', 'ace/worker/worker_client'], function(require, exports, module) {
  38. "use strict";
  39. var oop = require("../lib/oop");
  40. var TextMode = require("./text").Mode;
  41. var Tokenizer = require("../tokenizer").Tokenizer;
  42. var HighlightRules = require("./json_highlight_rules").JsonHighlightRules;
  43. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  44. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  45. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  46. var WorkerClient = require("../worker/worker_client").WorkerClient;
  47. var Mode = function() {
  48. this.$tokenizer = new Tokenizer(new HighlightRules().getRules());
  49. this.$outdent = new MatchingBraceOutdent();
  50. this.$behaviour = new CstyleBehaviour();
  51. this.foldingRules = new CStyleFoldMode();
  52. };
  53. oop.inherits(Mode, TextMode);
  54. (function() {
  55. this.getNextLineIndent = function(state, line, tab) {
  56. var indent = this.$getIndent(line);
  57. if (state == "start") {
  58. var match = line.match(/^.*[\{\(\[]\s*$/);
  59. if (match) {
  60. indent += tab;
  61. }
  62. }
  63. return indent;
  64. };
  65. this.checkOutdent = function(state, line, input) {
  66. return this.$outdent.checkOutdent(line, input);
  67. };
  68. this.autoOutdent = function(state, doc, row) {
  69. this.$outdent.autoOutdent(doc, row);
  70. };
  71. this.createWorker = function(session) {
  72. var worker = new WorkerClient(["ace"], "worker-json.js", "ace/mode/json_worker", "JsonWorker");
  73. worker.attachToDocument(session.getDocument());
  74. worker.on("error", function(e) {
  75. session.setAnnotations([e.data]);
  76. });
  77. worker.on("ok", function() {
  78. session.clearAnnotations();
  79. });
  80. return worker;
  81. };
  82. }).call(Mode.prototype);
  83. exports.Mode = Mode;
  84. });/* ***** BEGIN LICENSE BLOCK *****
  85. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  86. *
  87. * The contents of this file are subject to the Mozilla Public License Version
  88. * 1.1 (the "License"); you may not use this file except in compliance with
  89. * the License. You may obtain a copy of the License at
  90. * http://www.mozilla.org/MPL/
  91. *
  92. * Software distributed under the License is distributed on an "AS IS" basis,
  93. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  94. * for the specific language governing rights and limitations under the
  95. * License.
  96. *
  97. * The Original Code is Ajax.org Code Editor (ACE).
  98. *
  99. * The Initial Developer of the Original Code is
  100. * Ajax.org B.V.
  101. * Portions created by the Initial Developer are Copyright (C) 2010
  102. * the Initial Developer. All Rights Reserved.
  103. *
  104. * Contributor(s):
  105. * Fabian Jakobs <fabian AT ajax DOT org>
  106. * Mihai Sucan <mihai DOT sucan AT gmail DOT com>
  107. *
  108. * Alternatively, the contents of this file may be used under the terms of
  109. * either the GNU General Public License Version 2 or later (the "GPL"), or
  110. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  111. * in which case the provisions of the GPL or the LGPL are applicable instead
  112. * of those above. If you wish to allow use of your version of this file only
  113. * under the terms of either the GPL or the LGPL, and not to allow others to
  114. * use your version of this file under the terms of the MPL, indicate your
  115. * decision by deleting the provisions above and replace them with the notice
  116. * and other provisions required by the GPL or the LGPL. If you do not delete
  117. * the provisions above, a recipient may use your version of this file under
  118. * the terms of any one of the MPL, the GPL or the LGPL.
  119. *
  120. * ***** END LICENSE BLOCK ***** */
  121. define('ace/mode/json_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
  122. "use strict";
  123. var oop = require("../lib/oop");
  124. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  125. var JsonHighlightRules = function() {
  126. // regexp must not have capturing parentheses. Use (?:) instead.
  127. // regexps are ordered -> the first match is used
  128. this.$rules = {
  129. "start" : [
  130. {
  131. token : "string", // single line
  132. regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  133. }, {
  134. token : "constant.numeric", // hex
  135. regex : "0[xX][0-9a-fA-F]+\\b"
  136. }, {
  137. token : "constant.numeric", // float
  138. regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
  139. }, {
  140. token : "constant.language.boolean",
  141. regex : "(?:true|false)\\b"
  142. }, {
  143. token : "invalid.illegal", // single quoted strings are not allowed
  144. regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
  145. }, {
  146. token : "invalid.illegal", // comments are not allowed
  147. regex : "\\/\\/.*$"
  148. }, {
  149. token : "paren.lparen",
  150. regex : "[[({]"
  151. }, {
  152. token : "paren.rparen",
  153. regex : "[\\])}]"
  154. }, {
  155. token : "text",
  156. regex : "\\s+"
  157. }
  158. ]
  159. };
  160. };
  161. oop.inherits(JsonHighlightRules, TextHighlightRules);
  162. exports.JsonHighlightRules = JsonHighlightRules;
  163. });
  164. /* ***** BEGIN LICENSE BLOCK *****
  165. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  166. *
  167. * The contents of this file are subject to the Mozilla Public License Version
  168. * 1.1 (the "License"); you may not use this file except in compliance with
  169. * the License. You may obtain a copy of the License at
  170. * http://www.mozilla.org/MPL/
  171. *
  172. * Software distributed under the License is distributed on an "AS IS" basis,
  173. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  174. * for the specific language governing rights and limitations under the
  175. * License.
  176. *
  177. * The Original Code is Ajax.org Code Editor (ACE).
  178. *
  179. * The Initial Developer of the Original Code is
  180. * Ajax.org B.V.
  181. * Portions created by the Initial Developer are Copyright (C) 2010
  182. * the Initial Developer. All Rights Reserved.
  183. *
  184. * Contributor(s):
  185. * Fabian Jakobs <fabian AT ajax DOT org>
  186. *
  187. * Alternatively, the contents of this file may be used under the terms of
  188. * either the GNU General Public License Version 2 or later (the "GPL"), or
  189. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  190. * in which case the provisions of the GPL or the LGPL are applicable instead
  191. * of those above. If you wish to allow use of your version of this file only
  192. * under the terms of either the GPL or the LGPL, and not to allow others to
  193. * use your version of this file under the terms of the MPL, indicate your
  194. * decision by deleting the provisions above and replace them with the notice
  195. * and other provisions required by the GPL or the LGPL. If you do not delete
  196. * the provisions above, a recipient may use your version of this file under
  197. * the terms of any one of the MPL, the GPL or the LGPL.
  198. *
  199. * ***** END LICENSE BLOCK ***** */
  200. define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
  201. "use strict";
  202. var Range = require("../range").Range;
  203. var MatchingBraceOutdent = function() {};
  204. (function() {
  205. this.checkOutdent = function(line, input) {
  206. if (! /^\s+$/.test(line))
  207. return false;
  208. return /^\s*\}/.test(input);
  209. };
  210. this.autoOutdent = function(doc, row) {
  211. var line = doc.getLine(row);
  212. var match = line.match(/^(\s*\})/);
  213. if (!match) return 0;
  214. var column = match[1].length;
  215. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  216. if (!openBracePos || openBracePos.row == row) return 0;
  217. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  218. doc.replace(new Range(row, 0, row, column-1), indent);
  219. };
  220. this.$getIndent = function(line) {
  221. var match = line.match(/^(\s+)/);
  222. if (match) {
  223. return match[1];
  224. }
  225. return "";
  226. };
  227. }).call(MatchingBraceOutdent.prototype);
  228. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  229. });
  230. /* vim:ts=4:sts=4:sw=4:
  231. * ***** BEGIN LICENSE BLOCK *****
  232. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  233. *
  234. * The contents of this file are subject to the Mozilla Public License Version
  235. * 1.1 (the "License"); you may not use this file except in compliance with
  236. * the License. You may obtain a copy of the License at
  237. * http://www.mozilla.org/MPL/
  238. *
  239. * Software distributed under the License is distributed on an "AS IS" basis,
  240. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  241. * for the specific language governing rights and limitations under the
  242. * License.
  243. *
  244. * The Original Code is Ajax.org Code Editor (ACE).
  245. *
  246. * The Initial Developer of the Original Code is
  247. * Ajax.org B.V.
  248. * Portions created by the Initial Developer are Copyright (C) 2010
  249. * the Initial Developer. All Rights Reserved.
  250. *
  251. * Contributor(s):
  252. * Chris Spencer <chris.ag.spencer AT googlemail DOT com>
  253. *
  254. * Alternatively, the contents of this file may be used under the terms of
  255. * either the GNU General Public License Version 2 or later (the "GPL"), or
  256. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  257. * in which case the provisions of the GPL or the LGPL are applicable instead
  258. * of those above. If you wish to allow use of your version of this file only
  259. * under the terms of either the GPL or the LGPL, and not to allow others to
  260. * use your version of this file under the terms of the MPL, indicate your
  261. * decision by deleting the provisions above and replace them with the notice
  262. * and other provisions required by the GPL or the LGPL. If you do not delete
  263. * the provisions above, a recipient may use your version of this file under
  264. * the terms of any one of the MPL, the GPL or the LGPL.
  265. *
  266. * ***** END LICENSE BLOCK ***** */
  267. define('ace/mode/behaviour/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/behaviour'], function(require, exports, module) {
  268. "use strict";
  269. var oop = require("../../lib/oop");
  270. var Behaviour = require('../behaviour').Behaviour;
  271. var CstyleBehaviour = function () {
  272. this.add("braces", "insertion", function (state, action, editor, session, text) {
  273. if (text == '{') {
  274. var selection = editor.getSelectionRange();
  275. var selected = session.doc.getTextRange(selection);
  276. if (selected !== "") {
  277. return {
  278. text: '{' + selected + '}',
  279. selection: false
  280. };
  281. } else {
  282. return {
  283. text: '{}',
  284. selection: [1, 1]
  285. };
  286. }
  287. } else if (text == '}') {
  288. var cursor = editor.getCursorPosition();
  289. var line = session.doc.getLine(cursor.row);
  290. var rightChar = line.substring(cursor.column, cursor.column + 1);
  291. if (rightChar == '}') {
  292. var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
  293. if (matching !== null) {
  294. return {
  295. text: '',
  296. selection: [1, 1]
  297. };
  298. }
  299. }
  300. } else if (text == "\n") {
  301. var cursor = editor.getCursorPosition();
  302. var line = session.doc.getLine(cursor.row);
  303. var rightChar = line.substring(cursor.column, cursor.column + 1);
  304. if (rightChar == '}') {
  305. var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column + 1});
  306. if (!openBracePos)
  307. return null;
  308. var indent = this.getNextLineIndent(state, line.substring(0, line.length - 1), session.getTabString());
  309. var next_indent = this.$getIndent(session.doc.getLine(openBracePos.row));
  310. return {
  311. text: '\n' + indent + '\n' + next_indent,
  312. selection: [1, indent.length, 1, indent.length]
  313. };
  314. }
  315. }
  316. });
  317. this.add("braces", "deletion", function (state, action, editor, session, range) {
  318. var selected = session.doc.getTextRange(range);
  319. if (!range.isMultiLine() && selected == '{') {
  320. var line = session.doc.getLine(range.start.row);
  321. var rightChar = line.substring(range.end.column, range.end.column + 1);
  322. if (rightChar == '}') {
  323. range.end.column++;
  324. return range;
  325. }
  326. }
  327. });
  328. this.add("parens", "insertion", function (state, action, editor, session, text) {
  329. if (text == '(') {
  330. var selection = editor.getSelectionRange();
  331. var selected = session.doc.getTextRange(selection);
  332. if (selected !== "") {
  333. return {
  334. text: '(' + selected + ')',
  335. selection: false
  336. };
  337. } else {
  338. return {
  339. text: '()',
  340. selection: [1, 1]
  341. };
  342. }
  343. } else if (text == ')') {
  344. var cursor = editor.getCursorPosition();
  345. var line = session.doc.getLine(cursor.row);
  346. var rightChar = line.substring(cursor.column, cursor.column + 1);
  347. if (rightChar == ')') {
  348. var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
  349. if (matching !== null) {
  350. return {
  351. text: '',
  352. selection: [1, 1]
  353. };
  354. }
  355. }
  356. }
  357. });
  358. this.add("parens", "deletion", function (state, action, editor, session, range) {
  359. var selected = session.doc.getTextRange(range);
  360. if (!range.isMultiLine() && selected == '(') {
  361. var line = session.doc.getLine(range.start.row);
  362. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  363. if (rightChar == ')') {
  364. range.end.column++;
  365. return range;
  366. }
  367. }
  368. });
  369. this.add("string_dquotes", "insertion", function (state, action, editor, session, text) {
  370. if (text == '"' || text == "'") {
  371. var quote = text;
  372. var selection = editor.getSelectionRange();
  373. var selected = session.doc.getTextRange(selection);
  374. if (selected !== "") {
  375. return {
  376. text: quote + selected + quote,
  377. selection: false
  378. };
  379. } else {
  380. var cursor = editor.getCursorPosition();
  381. var line = session.doc.getLine(cursor.row);
  382. var leftChar = line.substring(cursor.column-1, cursor.column);
  383. // We're escaped.
  384. if (leftChar == '\\') {
  385. return null;
  386. }
  387. // Find what token we're inside.
  388. var tokens = session.getTokens(selection.start.row, selection.start.row)[0].tokens;
  389. var col = 0, token;
  390. var quotepos = -1; // Track whether we're inside an open quote.
  391. for (var x = 0; x < tokens.length; x++) {
  392. token = tokens[x];
  393. if (token.type == "string") {
  394. quotepos = -1;
  395. } else if (quotepos < 0) {
  396. quotepos = token.value.indexOf(quote);
  397. }
  398. if ((token.value.length + col) > selection.start.column) {
  399. break;
  400. }
  401. col += tokens[x].value.length;
  402. }
  403. // Try and be smart about when we auto insert.
  404. 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)))) {
  405. return {
  406. text: quote + quote,
  407. selection: [1,1]
  408. };
  409. } else if (token && token.type === "string") {
  410. // Ignore input and move right one if we're typing over the closing quote.
  411. var rightChar = line.substring(cursor.column, cursor.column + 1);
  412. if (rightChar == quote) {
  413. return {
  414. text: '',
  415. selection: [1, 1]
  416. };
  417. }
  418. }
  419. }
  420. }
  421. });
  422. this.add("string_dquotes", "deletion", function (state, action, editor, session, range) {
  423. var selected = session.doc.getTextRange(range);
  424. if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
  425. var line = session.doc.getLine(range.start.row);
  426. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  427. if (rightChar == '"') {
  428. range.end.column++;
  429. return range;
  430. }
  431. }
  432. });
  433. };
  434. oop.inherits(CstyleBehaviour, Behaviour);
  435. exports.CstyleBehaviour = CstyleBehaviour;
  436. });/* ***** BEGIN LICENSE BLOCK *****
  437. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  438. *
  439. * The contents of this file are subject to the Mozilla Public License Version
  440. * 1.1 (the "License"); you may not use this file except in compliance with
  441. * the License. You may obtain a copy of the License at
  442. * http://www.mozilla.org/MPL/
  443. *
  444. * Software distributed under the License is distributed on an "AS IS" basis,
  445. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  446. * for the specific language governing rights and limitations under the
  447. * License.
  448. *
  449. * The Original Code is Ajax.org Code Editor (ACE).
  450. *
  451. * The Initial Developer of the Original Code is
  452. * Ajax.org B.V.
  453. * Portions created by the Initial Developer are Copyright (C) 2010
  454. * the Initial Developer. All Rights Reserved.
  455. *
  456. * Contributor(s):
  457. * Fabian Jakobs <fabian AT ajax DOT org>
  458. *
  459. * Alternatively, the contents of this file may be used under the terms of
  460. * either the GNU General Public License Version 2 or later (the "GPL"), or
  461. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  462. * in which case the provisions of the GPL or the LGPL are applicable instead
  463. * of those above. If you wish to allow use of your version of this file only
  464. * under the terms of either the GPL or the LGPL, and not to allow others to
  465. * use your version of this file under the terms of the MPL, indicate your
  466. * decision by deleting the provisions above and replace them with the notice
  467. * and other provisions required by the GPL or the LGPL. If you do not delete
  468. * the provisions above, a recipient may use your version of this file under
  469. * the terms of any one of the MPL, the GPL or the LGPL.
  470. *
  471. * ***** END LICENSE BLOCK ***** */
  472. define('ace/mode/folding/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/range', 'ace/mode/folding/fold_mode'], function(require, exports, module) {
  473. "use strict";
  474. var oop = require("../../lib/oop");
  475. var Range = require("../../range").Range;
  476. var BaseFoldMode = require("./fold_mode").FoldMode;
  477. var FoldMode = exports.FoldMode = function() {};
  478. oop.inherits(FoldMode, BaseFoldMode);
  479. (function() {
  480. this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
  481. this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
  482. this.getFoldWidgetRange = function(session, foldStyle, row) {
  483. var line = session.getLine(row);
  484. var match = line.match(this.foldingStartMarker);
  485. if (match) {
  486. var i = match.index;
  487. if (match[1])
  488. return this.openingBracketBlock(session, match[1], row, i);
  489. var range = session.getCommentFoldRange(row, i + match[0].length);
  490. range.end.column -= 2;
  491. return range;
  492. }
  493. if (foldStyle !== "markbeginend")
  494. return;
  495. var match = line.match(this.foldingStopMarker);
  496. if (match) {
  497. var i = match.index + match[0].length;
  498. if (match[2]) {
  499. var range = session.getCommentFoldRange(row, i);
  500. range.end.column -= 2;
  501. return range;
  502. }
  503. var end = {row: row, column: i};
  504. var start = session.$findOpeningBracket(match[1], end);
  505. if (!start)
  506. return;
  507. start.column++;
  508. end.column--;
  509. return Range.fromPoints(start, end);
  510. }
  511. };
  512. }).call(FoldMode.prototype);
  513. });/* ***** BEGIN LICENSE BLOCK *****
  514. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  515. *
  516. * The contents of this file are subject to the Mozilla Public License Version
  517. * 1.1 (the "License"); you may not use this file except in compliance with
  518. * the License. You may obtain a copy of the License at
  519. * http://www.mozilla.org/MPL/
  520. *
  521. * Software distributed under the License is distributed on an "AS IS" basis,
  522. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  523. * for the specific language governing rights and limitations under the
  524. * License.
  525. *
  526. * The Original Code is Ajax.org Code Editor (ACE).
  527. *
  528. * The Initial Developer of the Original Code is
  529. * Ajax.org B.V.
  530. * Portions created by the Initial Developer are Copyright (C) 2010
  531. * the Initial Developer. All Rights Reserved.
  532. *
  533. * Contributor(s):
  534. * Fabian Jakobs <fabian AT ajax DOT org>
  535. *
  536. * Alternatively, the contents of this file may be used under the terms of
  537. * either the GNU General Public License Version 2 or later (the "GPL"), or
  538. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  539. * in which case the provisions of the GPL or the LGPL are applicable instead
  540. * of those above. If you wish to allow use of your version of this file only
  541. * under the terms of either the GPL or the LGPL, and not to allow others to
  542. * use your version of this file under the terms of the MPL, indicate your
  543. * decision by deleting the provisions above and replace them with the notice
  544. * and other provisions required by the GPL or the LGPL. If you do not delete
  545. * the provisions above, a recipient may use your version of this file under
  546. * the terms of any one of the MPL, the GPL or the LGPL.
  547. *
  548. * ***** END LICENSE BLOCK ***** */
  549. define('ace/mode/folding/fold_mode', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
  550. "use strict";
  551. var Range = require("../../range").Range;
  552. var FoldMode = exports.FoldMode = function() {};
  553. (function() {
  554. this.foldingStartMarker = null;
  555. this.foldingStopMarker = null;
  556. // must return "" if there's no fold, to enable caching
  557. this.getFoldWidget = function(session, foldStyle, row) {
  558. var line = session.getLine(row);
  559. if (this.foldingStartMarker.test(line))
  560. return "start";
  561. if (foldStyle == "markbeginend"
  562. && this.foldingStopMarker
  563. && this.foldingStopMarker.test(line))
  564. return "end";
  565. return "";
  566. };
  567. this.getFoldWidgetRange = function(session, foldStyle, row) {
  568. return null;
  569. };
  570. this.indentationBlock = function(session, row, column) {
  571. var re = /^\s*/;
  572. var startRow = row;
  573. var endRow = row;
  574. var line = session.getLine(row);
  575. var startColumn = column || line.length;
  576. var startLevel = line.match(re)[0].length;
  577. var maxRow = session.getLength()
  578. while (++row < maxRow) {
  579. line = session.getLine(row);
  580. var level = line.match(re)[0].length;
  581. if (level == line.length)
  582. continue;
  583. if (level <= startLevel)
  584. break;
  585. endRow = row;
  586. }
  587. if (endRow > startRow) {
  588. var endColumn = session.getLine(endRow).length;
  589. return new Range(startRow, startColumn, endRow, endColumn);
  590. }
  591. };
  592. this.openingBracketBlock = function(session, bracket, row, column) {
  593. var start = {row: row, column: column + 1};
  594. var end = session.$findClosingBracket(bracket, start);
  595. if (!end)
  596. return;
  597. var fw = session.foldWidgets[end.row];
  598. if (fw == null)
  599. fw = this.getFoldWidget(session, end.row);
  600. if (fw == "start") {
  601. end.row --;
  602. end.column = session.getLine(end.row).length;
  603. }
  604. return Range.fromPoints(start, end);
  605. };
  606. }).call(FoldMode.prototype);
  607. });