LaravelTest

Форк
0
159 строк · 4.9 Кб
1
// CodeMirror, copyright (c) by Marijn Haverbeke and others
2
// Distributed under an MIT license: https://codemirror.net/LICENSE
3

4
(function(mod) {
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
6
    mod(require("../../lib/codemirror"));
7
  else if (typeof define == "function" && define.amd) // AMD
8
    define(["../../lib/codemirror"], mod);
9
  else // Plain browser env
10
    mod(CodeMirror);
11
})(function(CodeMirror) {
12
  "use strict";
13

14
  function doFold(cm, pos, options, force) {
15
    if (options && options.call) {
16
      var finder = options;
17
      options = null;
18
    } else {
19
      var finder = getOption(cm, options, "rangeFinder");
20
    }
21
    if (typeof pos == "number") pos = CodeMirror.Pos(pos, 0);
22
    var minSize = getOption(cm, options, "minFoldSize");
23

24
    function getRange(allowFolded) {
25
      var range = finder(cm, pos);
26
      if (!range || range.to.line - range.from.line < minSize) return null;
27
      if (force === "fold") return range;
28

29
      var marks = cm.findMarksAt(range.from);
30
      for (var i = 0; i < marks.length; ++i) {
31
        if (marks[i].__isFold) {
32
          if (!allowFolded) return null;
33
          range.cleared = true;
34
          marks[i].clear();
35
        }
36
      }
37
      return range;
38
    }
39

40
    var range = getRange(true);
41
    if (getOption(cm, options, "scanUp")) while (!range && pos.line > cm.firstLine()) {
42
      pos = CodeMirror.Pos(pos.line - 1, 0);
43
      range = getRange(false);
44
    }
45
    if (!range || range.cleared || force === "unfold") return;
46

47
    var myWidget = makeWidget(cm, options, range);
48
    CodeMirror.on(myWidget, "mousedown", function(e) {
49
      myRange.clear();
50
      CodeMirror.e_preventDefault(e);
51
    });
52
    var myRange = cm.markText(range.from, range.to, {
53
      replacedWith: myWidget,
54
      clearOnEnter: getOption(cm, options, "clearOnEnter"),
55
      __isFold: true
56
    });
57
    myRange.on("clear", function(from, to) {
58
      CodeMirror.signal(cm, "unfold", cm, from, to);
59
    });
60
    CodeMirror.signal(cm, "fold", cm, range.from, range.to);
61
  }
62

63
  function makeWidget(cm, options, range) {
64
    var widget = getOption(cm, options, "widget");
65

66
    if (typeof widget == "function") {
67
      widget = widget(range.from, range.to);
68
    }
69

70
    if (typeof widget == "string") {
71
      var text = document.createTextNode(widget);
72
      widget = document.createElement("span");
73
      widget.appendChild(text);
74
      widget.className = "CodeMirror-foldmarker";
75
    } else if (widget) {
76
      widget = widget.cloneNode(true)
77
    }
78
    return widget;
79
  }
80

81
  // Clumsy backwards-compatible interface
82
  CodeMirror.newFoldFunction = function(rangeFinder, widget) {
83
    return function(cm, pos) { doFold(cm, pos, {rangeFinder: rangeFinder, widget: widget}); };
84
  };
85

86
  // New-style interface
87
  CodeMirror.defineExtension("foldCode", function(pos, options, force) {
88
    doFold(this, pos, options, force);
89
  });
90

91
  CodeMirror.defineExtension("isFolded", function(pos) {
92
    var marks = this.findMarksAt(pos);
93
    for (var i = 0; i < marks.length; ++i)
94
      if (marks[i].__isFold) return true;
95
  });
96

97
  CodeMirror.commands.toggleFold = function(cm) {
98
    cm.foldCode(cm.getCursor());
99
  };
100
  CodeMirror.commands.fold = function(cm) {
101
    cm.foldCode(cm.getCursor(), null, "fold");
102
  };
103
  CodeMirror.commands.unfold = function(cm) {
104
    cm.foldCode(cm.getCursor(), { scanUp: false }, "unfold");
105
  };
106
  CodeMirror.commands.foldAll = function(cm) {
107
    cm.operation(function() {
108
      for (var i = cm.firstLine(), e = cm.lastLine(); i <= e; i++)
109
        cm.foldCode(CodeMirror.Pos(i, 0), { scanUp: false }, "fold");
110
    });
111
  };
112
  CodeMirror.commands.unfoldAll = function(cm) {
113
    cm.operation(function() {
114
      for (var i = cm.firstLine(), e = cm.lastLine(); i <= e; i++)
115
        cm.foldCode(CodeMirror.Pos(i, 0), { scanUp: false }, "unfold");
116
    });
117
  };
118

119
  CodeMirror.registerHelper("fold", "combine", function() {
120
    var funcs = Array.prototype.slice.call(arguments, 0);
121
    return function(cm, start) {
122
      for (var i = 0; i < funcs.length; ++i) {
123
        var found = funcs[i](cm, start);
124
        if (found) return found;
125
      }
126
    };
127
  });
128

129
  CodeMirror.registerHelper("fold", "auto", function(cm, start) {
130
    var helpers = cm.getHelpers(start, "fold");
131
    for (var i = 0; i < helpers.length; i++) {
132
      var cur = helpers[i](cm, start);
133
      if (cur) return cur;
134
    }
135
  });
136

137
  var defaultOptions = {
138
    rangeFinder: CodeMirror.fold.auto,
139
    widget: "\u2194",
140
    minFoldSize: 0,
141
    scanUp: false,
142
    clearOnEnter: true
143
  };
144

145
  CodeMirror.defineOption("foldOptions", null);
146

147
  function getOption(cm, options, name) {
148
    if (options && options[name] !== undefined)
149
      return options[name];
150
    var editorOptions = cm.options.foldOptions;
151
    if (editorOptions && editorOptions[name] !== undefined)
152
      return editorOptions[name];
153
    return defaultOptions[name];
154
  }
155

156
  CodeMirror.defineExtension("foldOption", function(options, name) {
157
    return getOption(this, options, name);
158
  });
159
});
160

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.