|
71 | 71 | } |
72 | 72 |
|
73 | 73 | function updateFoldInfo(cm, from, to) { |
74 | | - var opts = cm.state.foldGutter.options, cur = from; |
| 74 | + var opts = cm.state.foldGutter.options, cur = from - 1; |
75 | 75 | var minSize = cm.foldOption(opts, "minFoldSize"); |
76 | 76 | 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); |
77 | 80 | cm.eachLine(from, to, function(line) { |
| 81 | + ++cur; |
78 | 82 | var mark = null; |
| 83 | + var old = line.gutterMarkers; |
| 84 | + if (old) old = old[opts.gutter]; |
79 | 85 | if (isFolded(cm, cur)) { |
| 86 | + if (clsFolded && old && clsFolded.test(old.className)) return; |
80 | 87 | mark = marker(opts.indicatorFolded); |
81 | 88 | } else { |
82 | 89 | var pos = Pos(cur, 0); |
83 | 90 | 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; |
85 | 93 | mark = marker(opts.indicatorOpen); |
| 94 | + } |
86 | 95 | } |
| 96 | + if (!mark && !old) return; |
87 | 97 | cm.setGutterMarker(line, opts.gutter, mark); |
88 | | - ++cur; |
89 | 98 | }); |
90 | 99 | } |
91 | 100 |
|
| 101 | + // copied from CodeMirror/src/util/dom.js |
| 102 | + function classTest(cls) { return new RegExp("(^|\\s)" + cls + "(?:$|\\s)\\s*") } |
| 103 | + |
92 | 104 | function updateInViewport(cm) { |
93 | 105 | var vp = cm.getViewport(), state = cm.state.foldGutter; |
94 | 106 | if (!state) return; |
|
0 commit comments