1
0
mirror of https://github.com/adobe/brackets.git synced 2024-11-20 18:02:54 +01:00

documented and refactored restoreLineFolds function

This commit is contained in:
Patrick Oladimeji 2015-08-09 08:50:13 -04:00
parent 853b5d1af3
commit dd3be9f799

View File

@ -86,11 +86,33 @@ define(function (require, exports, module) {
* @param {Editor} editor the editor whose saved line folds should be restored
*/
function restoreLineFolds(editor) {
function isInViewStateSelection(range, selection) {
/**
* Checks if the range from and to Pos is the same as the selection start and end Pos
* @param {Object} range {from, to} where from and to are CodeMirror.Pos objects
* @param {Object} selection {start, end} where start and end are CodeMirror.Pos objects
* @returns {Boolean} true if the range and selection span the same region and false otherwise
*/
function rangeEqualsSelection(range, selection) {
return range.from.line === selection.start.line && range.from.ch === selection.start.ch &&
range.to.line === selection.end.line && range.to.ch === selection.end.ch;
}
/**
* Checks if the range is equal to one of the selections in the viewState
* @param {Object} range {from, to} where from and to are CodeMirror.Pos objects.
* @param {Object} viewState The current editor's ViewState object
* @returns {Boolean} true if the range is found in the list of selections or false if not.
*/
function isInViewStateSelection(range, viewState) {
if (!viewState || !viewState.selections) {
return false;
}
return viewState.selections.some(function (selection) {
return rangeEqualsSelection(range, selection);
});
}
var saveFolds = prefs.getSetting("saveFoldStates");
if (!editor || !saveFolds) {
return;
@ -103,9 +125,7 @@ define(function (require, exports, module) {
var nonSelectionFolds = {}, selectionFolds = {}, range;
Object.keys(folds).forEach(function (line) {
range = folds[line];
if (viewState.selections && viewState.selections.some(function (selection) {
return isInViewStateSelection(range, selection);
})) {
if (isInViewStateSelection(range, viewState)) {
selectionFolds[line] = range;
} else {
nonSelectionFolds[line] = range;