Skip to content

Commit f6934da

Browse files
authored
Improve folding addon performance
* Exit method early of mode is 'fold' instead of iterating * Don't scanUp when iterating over every line of document * Don't scanUp for forced unfolds (has no effect)
1 parent 579e120 commit f6934da

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

addon/fold/foldcode.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
function getRange(allowFolded) {
2525
var range = finder(cm, pos);
2626
if (!range || range.to.line - range.from.line < minSize) return null;
27+
if (force === "fold") return range;
28+
2729
var marks = cm.findMarksAt(range.from);
2830
for (var i = 0; i < marks.length; ++i) {
29-
if (marks[i].__isFold && force !== "fold") {
31+
if (marks[i].__isFold) {
3032
if (!allowFolded) return null;
3133
range.cleared = true;
3234
marks[i].clear();
@@ -99,18 +101,18 @@
99101
cm.foldCode(cm.getCursor(), null, "fold");
100102
};
101103
CodeMirror.commands.unfold = function(cm) {
102-
cm.foldCode(cm.getCursor(), null, "unfold");
104+
cm.foldCode(cm.getCursor(), { scanUp: false }, "unfold");
103105
};
104106
CodeMirror.commands.foldAll = function(cm) {
105107
cm.operation(function() {
106108
for (var i = cm.firstLine(), e = cm.lastLine(); i <= e; i++)
107-
cm.foldCode(CodeMirror.Pos(i, 0), null, "fold");
109+
cm.foldCode(CodeMirror.Pos(i, 0), { scanUp: false }, "fold");
108110
});
109111
};
110112
CodeMirror.commands.unfoldAll = function(cm) {
111113
cm.operation(function() {
112114
for (var i = cm.firstLine(), e = cm.lastLine(); i <= e; i++)
113-
cm.foldCode(CodeMirror.Pos(i, 0), null, "unfold");
115+
cm.foldCode(CodeMirror.Pos(i, 0), { scanUp: false }, "unfold");
114116
});
115117
};
116118

0 commit comments

Comments
 (0)