mode-diff.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. ace.define("ace/mode/diff_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 DiffHighlightRules = function() {
  6. this.$rules = {
  7. "start" : [{
  8. regex: "^(?:\\*{15}|={67}|-{3}|\\+{3})$",
  9. token: "punctuation.definition.separator.diff",
  10. "name": "keyword"
  11. }, { //diff.range.unified
  12. regex: "^(@@)(\\s*.+?\\s*)(@@)(.*)$",
  13. token: [
  14. "constant",
  15. "constant.numeric",
  16. "constant",
  17. "comment.doc.tag"
  18. ]
  19. }, { //diff.range.normal
  20. regex: "^(\\d+)([,\\d]+)(a|d|c)(\\d+)([,\\d]+)(.*)$",
  21. token: [
  22. "constant.numeric",
  23. "punctuation.definition.range.diff",
  24. "constant.function",
  25. "constant.numeric",
  26. "punctuation.definition.range.diff",
  27. "invalid"
  28. ],
  29. "name": "meta."
  30. }, {
  31. regex: "^(\\-{3}|\\+{3}|\\*{3})( .+)$",
  32. token: [
  33. "constant.numeric",
  34. "meta.tag"
  35. ]
  36. }, { // added
  37. regex: "^([!+>])(.*?)(\\s*)$",
  38. token: [
  39. "support.constant",
  40. "text",
  41. "invalid"
  42. ]
  43. }, { // removed
  44. regex: "^([<\\-])(.*?)(\\s*)$",
  45. token: [
  46. "support.function",
  47. "string",
  48. "invalid"
  49. ]
  50. }, {
  51. regex: "^(diff)(\\s+--\\w+)?(.+?)( .+)?$",
  52. token: ["variable", "variable", "keyword", "variable"]
  53. }, {
  54. regex: "^Index.+$",
  55. token: "variable"
  56. }, {
  57. regex: "^\\s+$",
  58. token: "text"
  59. }, {
  60. regex: "\\s*$",
  61. token: "invalid"
  62. }, {
  63. defaultToken: "invisible",
  64. caseInsensitive: true
  65. }
  66. ]
  67. };
  68. };
  69. oop.inherits(DiffHighlightRules, TextHighlightRules);
  70. exports.DiffHighlightRules = DiffHighlightRules;
  71. });
  72. ace.define("ace/mode/folding/diff",["require","exports","module","ace/lib/oop","ace/mode/folding/fold_mode","ace/range"], function(require, exports, module) {
  73. "use strict";
  74. var oop = require("../../lib/oop");
  75. var BaseFoldMode = require("./fold_mode").FoldMode;
  76. var Range = require("../../range").Range;
  77. var FoldMode = exports.FoldMode = function(levels, flag) {
  78. this.regExpList = levels;
  79. this.flag = flag;
  80. this.foldingStartMarker = RegExp("^(" + levels.join("|") + ")", this.flag);
  81. };
  82. oop.inherits(FoldMode, BaseFoldMode);
  83. (function() {
  84. this.getFoldWidgetRange = function(session, foldStyle, row) {
  85. var line = session.getLine(row);
  86. var start = {row: row, column: line.length};
  87. var regList = this.regExpList;
  88. for (var i = 1; i <= regList.length; i++) {
  89. var re = RegExp("^(" + regList.slice(0, i).join("|") + ")", this.flag);
  90. if (re.test(line))
  91. break;
  92. }
  93. for (var l = session.getLength(); ++row < l; ) {
  94. line = session.getLine(row);
  95. if (re.test(line))
  96. break;
  97. }
  98. if (row == start.row + 1)
  99. return;
  100. return Range.fromPoints(start, {row: row - 1, column: line.length});
  101. };
  102. }).call(FoldMode.prototype);
  103. });
  104. ace.define("ace/mode/diff",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/diff_highlight_rules","ace/mode/folding/diff"], function(require, exports, module) {
  105. "use strict";
  106. var oop = require("../lib/oop");
  107. var TextMode = require("./text").Mode;
  108. var HighlightRules = require("./diff_highlight_rules").DiffHighlightRules;
  109. var FoldMode = require("./folding/diff").FoldMode;
  110. var Mode = function() {
  111. this.HighlightRules = HighlightRules;
  112. this.foldingRules = new FoldMode(["diff", "index", "\\+{3}", "@@|\\*{5}"], "i");
  113. };
  114. oop.inherits(Mode, TextMode);
  115. (function() {
  116. this.$id = "ace/mode/diff";
  117. }).call(Mode.prototype);
  118. exports.Mode = Mode;
  119. });