Skip to content

Commit 6da9363

Browse files
tophfmarijnh
authored andcommitted
[foldgutter] reuse old markers if indicatorOpen/Folded is string
1 parent 1200b14 commit 6da9363

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

addon/fold/foldgutter.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,24 +71,36 @@
7171
}
7272

7373
function updateFoldInfo(cm, from, to) {
74-
var opts = cm.state.foldGutter.options, cur = from;
74+
var opts = cm.state.foldGutter.options, cur = from - 1;
7575
var minSize = cm.foldOption(opts, "minFoldSize");
7676
var func = cm.foldOption(opts, "rangeFinder");
77+
// we can reuse the built-in indicator element if its className matches the new state
78+
var clsFolded = typeof opts.indicatorFolded == "string" && classTest(opts.indicatorFolded);
79+
var clsOpen = typeof opts.indicatorOpen == "string" && classTest(opts.indicatorOpen);
7780
cm.eachLine(from, to, function(line) {
81+
++cur;
7882
var mark = null;
83+
var old = line.gutterMarkers;
84+
if (old) old = old[opts.gutter];
7985
if (isFolded(cm, cur)) {
86+
if (clsFolded && old && clsFolded.test(old.className)) return;
8087
mark = marker(opts.indicatorFolded);
8188
} else {
8289
var pos = Pos(cur, 0);
8390
var range = func && func(cm, pos);
84-
if (range && range.to.line - range.from.line >= minSize)
91+
if (range && range.to.line - range.from.line >= minSize) {
92+
if (clsOpen && old && clsOpen.test(old.className)) return;
8593
mark = marker(opts.indicatorOpen);
94+
}
8695
}
96+
if (!mark && !old) return;
8797
cm.setGutterMarker(line, opts.gutter, mark);
88-
++cur;
8998
});
9099
}
91100

101+
// copied from CodeMirror/src/util/dom.js
102+
function classTest(cls) { return new RegExp("(^|\\s)" + cls + "(?:$|\\s)\\s*") }
103+
92104
function updateInViewport(cm) {
93105
var vp = cm.getViewport(), state = cm.state.foldGutter;
94106
if (!state) return;

0 commit comments

Comments
 (0)