931d2d4721a07dc0cef85cc83d1dd6db.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. ace.define("ace/mode/folding/coffee",["require","exports","module","ace/lib/oop","ace/mode/folding/fold_mode","ace/range"], function(require, exports, module){"use strict";
  2. var oop = require("../../lib/oop");
  3. var BaseFoldMode = require("./fold_mode").FoldMode;
  4. var Range = require("../../range").Range;
  5. var FoldMode = exports.FoldMode = function () { };
  6. oop.inherits(FoldMode, BaseFoldMode);
  7. (function () {
  8. this.getFoldWidgetRange = function (session, foldStyle, row) {
  9. var range = this.indentationBlock(session, row);
  10. if (range)
  11. return range;
  12. var re = /\S/;
  13. var line = session.getLine(row);
  14. var startLevel = line.search(re);
  15. if (startLevel == -1 || line[startLevel] != "#")
  16. return;
  17. var startColumn = line.length;
  18. var maxRow = session.getLength();
  19. var startRow = row;
  20. var endRow = row;
  21. while (++row < maxRow) {
  22. line = session.getLine(row);
  23. var level = line.search(re);
  24. if (level == -1)
  25. continue;
  26. if (line[level] != "#")
  27. break;
  28. endRow = row;
  29. }
  30. if (endRow > startRow) {
  31. var endColumn = session.getLine(endRow).length;
  32. return new Range(startRow, startColumn, endRow, endColumn);
  33. }
  34. };
  35. this.getFoldWidget = function (session, foldStyle, row) {
  36. var line = session.getLine(row);
  37. var indent = line.search(/\S/);
  38. var next = session.getLine(row + 1);
  39. var prev = session.getLine(row - 1);
  40. var prevIndent = prev.search(/\S/);
  41. var nextIndent = next.search(/\S/);
  42. if (indent == -1) {
  43. session.foldWidgets[row - 1] = prevIndent != -1 && prevIndent < nextIndent ? "start" : "";
  44. return "";
  45. }
  46. if (prevIndent == -1) {
  47. if (indent == nextIndent && line[indent] == "#" && next[indent] == "#") {
  48. session.foldWidgets[row - 1] = "";
  49. session.foldWidgets[row + 1] = "";
  50. return "start";
  51. }
  52. }
  53. else if (prevIndent == indent && line[indent] == "#" && prev[indent] == "#") {
  54. if (session.getLine(row - 2).search(/\S/) == -1) {
  55. session.foldWidgets[row - 1] = "start";
  56. session.foldWidgets[row + 1] = "";
  57. return "";
  58. }
  59. }
  60. if (prevIndent != -1 && prevIndent < indent)
  61. session.foldWidgets[row - 1] = "start";
  62. else
  63. session.foldWidgets[row - 1] = "";
  64. if (indent < nextIndent)
  65. return "start";
  66. else
  67. return "";
  68. };
  69. }).call(FoldMode.prototype);
  70. });
  71. ace.define("ace/mode/space_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module){"use strict";
  72. var oop = require("../lib/oop");
  73. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  74. var SpaceHighlightRules = function () {
  75. this.$rules = {
  76. "start": [
  77. {
  78. token: "empty_line",
  79. regex: / */,
  80. next: "key"
  81. },
  82. {
  83. token: "empty_line",
  84. regex: /$/,
  85. next: "key"
  86. }
  87. ],
  88. "key": [
  89. {
  90. token: "variable",
  91. regex: /\S+/
  92. },
  93. {
  94. token: "empty_line",
  95. regex: /$/,
  96. next: "start"
  97. }, {
  98. token: "keyword.operator",
  99. regex: / /,
  100. next: "value"
  101. }
  102. ],
  103. "value": [
  104. {
  105. token: "keyword.operator",
  106. regex: /$/,
  107. next: "start"
  108. },
  109. {
  110. token: "string",
  111. regex: /[^$]/
  112. }
  113. ]
  114. };
  115. };
  116. oop.inherits(SpaceHighlightRules, TextHighlightRules);
  117. exports.SpaceHighlightRules = SpaceHighlightRules;
  118. });
  119. ace.define("ace/mode/space",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/folding/coffee","ace/mode/space_highlight_rules"], function(require, exports, module){"use strict";
  120. var oop = require("../lib/oop");
  121. var TextMode = require("./text").Mode;
  122. var FoldMode = require("./folding/coffee").FoldMode;
  123. var SpaceHighlightRules = require("./space_highlight_rules").SpaceHighlightRules;
  124. var Mode = function () {
  125. this.HighlightRules = SpaceHighlightRules;
  126. this.foldingRules = new FoldMode();
  127. this.$behaviour = this.$defaultBehaviour;
  128. };
  129. oop.inherits(Mode, TextMode);
  130. (function () {
  131. this.$id = "ace/mode/space";
  132. }).call(Mode.prototype);
  133. exports.Mode = Mode;
  134. }); (function() {
  135. ace.require(["ace/mode/space"], function(m) {
  136. if (typeof module == "object" && typeof exports == "object" && module) {
  137. module.exports = m;
  138. }
  139. });
  140. })();