Skip to content

Commit fe530e4

Browse files
author
Mohsen Azimi
committed
Update fold-manager to support two way deep fold sync
#81
1 parent 3abfbeb commit fe530e4

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

app/scripts/services/fold-manager.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,38 @@ function FoldManager(Editor, FoldPointFinder) {
4141
return current;
4242
}
4343

44+
/*
45+
** Beneath first search for the fold that has the same start
46+
*/
47+
function scan(current, start) {
48+
var result = null;
49+
var node, fold;
50+
51+
if (current.start === start) {
52+
return current;
53+
}
54+
55+
if (angular.isObject(current.subFolds)) {
56+
for (var k in current.subFolds) {
57+
if (angular.isObject(current.subFolds)) {
58+
node = current.subFolds[k];
59+
fold = scan(node, start);
60+
if (fold) {
61+
result = fold;
62+
}
63+
}
64+
}
65+
}
66+
67+
return result;
68+
}
69+
4470
Editor.onFoldChanged(function (change) {
45-
var key = Editor.getLine(change.data.start.row).trim().replace(':', '');
71+
var row = change.data.start.row;
4672
var folded = change.action !== 'remove';
73+
var fold = scan(buffer, row);
4774

48-
if (buffer[key]) {
49-
buffer[key].folded = folded;
50-
}
75+
fold.folded = folded;
5176

5277
emitChanges();
5378
});

0 commit comments

Comments
 (0)