mode-space.js 4.7 KB

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