Skip to content

Commit b628507

Browse files
author
Mohsen Azimi
committed
Document up fold manager #81
1 parent fe530e4 commit b628507

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

app/scripts/services/fold-manager.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,34 @@ function FoldManager(Editor, FoldPointFinder) {
1111

1212
Editor.ready(renewBuffer);
1313

14+
/*
15+
** Update buffer with changes from editor
16+
*/
1417
function refreshBuffer() {
1518
_.extend(buffer, FoldPointFinder.findFolds(Editor.getValue()));
1619
emitChanges();
1720
}
1821

22+
/*
23+
** Flush buffer and put new value in the buffer
24+
*/
1925
function renewBuffer() {
2026
buffer = FoldPointFinder.findFolds(Editor.getValue());
2127
emitChanges();
2228
}
2329

30+
/*
31+
** Let event listeners know there was a change in fold status
32+
*/
2433
function emitChanges() {
2534
changeListeners.forEach(function (fn) {
2635
fn();
2736
});
2837
}
2938

39+
/*
40+
** Walk the buffer tree for a given path
41+
*/
3042
function walk(keys) {
3143
var current = buffer;
3244

@@ -67,6 +79,9 @@ function FoldManager(Editor, FoldPointFinder) {
6779
return result;
6880
}
6981

82+
/*
83+
** Listen to fold changes in editor and reflect it in buffer
84+
*/
7085
Editor.onFoldChanged(function (change) {
7186
var row = change.data.start.row;
7287
var folded = change.action !== 'remove';
@@ -77,6 +92,9 @@ function FoldManager(Editor, FoldPointFinder) {
7792
emitChanges();
7893
});
7994

95+
/*
96+
** Toggle a fold status and reflect it in the editor
97+
*/
8098
this.toggleFold = function () {
8199
var keys = [].slice.call(arguments, 0);
82100
var fold = walk(keys);
@@ -90,17 +108,24 @@ function FoldManager(Editor, FoldPointFinder) {
90108
}
91109
};
92110

111+
/*
112+
** Return status of a fold with given path parameters
113+
*/
93114
this.isFolded = function () {
94115
var keys = [].slice.call(arguments, 0);
95116
var fold = walk(keys);
96117

97118
return fold && fold.folded;
98119
};
99120

121+
/*
122+
** Fold status change listener installer
123+
*/
100124
this.onFoldStatusChanged = function (fn) {
101125
changeListeners.push(fn);
102126
};
103127

128+
// Expose the methods externally
104129
this.reset = renewBuffer;
105130
this.refresh = refreshBuffer;
106131
}

0 commit comments

Comments
 (0)