diff --git a/src/extensions/default/CodeFolding/main.js b/src/extensions/default/CodeFolding/main.js index 18d3844ebc0..0e6f4e35b1a 100644 --- a/src/extensions/default/CodeFolding/main.js +++ b/src/extensions/default/CodeFolding/main.js @@ -117,13 +117,19 @@ define(function (require, exports, module) { } var saveFolds = prefs.getSetting("saveFoldStates"); + if (!editor || !saveFolds) { + if (editor) { + editor._codeMirror._lineFolds = editor._codeMirror._lineFolds || {}; + } return; } - var viewState = ViewStateManager.getViewState(editor.document.file); + var cm = editor._codeMirror; + var viewState = ViewStateManager.getViewState(editor.document.file); var path = editor.document.file.fullPath; var folds = cm._lineFolds || prefs.getFolds(path) || {}; + //separate out selection folds from non-selection folds var nonSelectionFolds = {}, selectionFolds = {}, range; Object.keys(folds).forEach(function (line) { diff --git a/src/extensions/default/CodeFolding/unittests.js b/src/extensions/default/CodeFolding/unittests.js index eaef8d2ae2f..09f26064b8f 100644 --- a/src/extensions/default/CodeFolding/unittests.js +++ b/src/extensions/default/CodeFolding/unittests.js @@ -399,6 +399,14 @@ define(function (require, exports, module) { var marks = getEditorFoldMarks(); expect(marks.length).toEqual(0); }); + + runs(function () { + var lineNumbers = foldableLines; + var marks = getGutterFoldMarks(); + var gutterNumbers = marks.filter(filterOpen) + .map(getLineNumber); + expect(gutterNumbers).toEqual(toZeroIndex(lineNumbers)); + }); }); it("can set the minimum fold size", function () {