-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Addresses issue #10846 #10850
Addresses issue #10846 #10850
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,27 +8,35 @@ | |
/*global define, brackets*/ | ||
define(function (require, exports, module) { | ||
"use strict"; | ||
var PreferencesManager = brackets.getModule("preferences/PreferencesManager"), | ||
prefs = PreferencesManager.getExtensionPrefs("code-folding"), | ||
strings = brackets.getModule("strings"), | ||
store = {}, | ||
foldsKey = "folds"; | ||
var PreferencesManager = brackets.getModule("preferences/PreferencesManager"), | ||
prefs = PreferencesManager.getExtensionPrefs("code-folding"), | ||
foldsKey = "code-folding.folds", | ||
// preference key strings are here for now since they are not used in any UI | ||
ENABLE_CODE_FOLDING = "Enable code folding", | ||
MIN_FOLD_SIZE = "Minimum fold size", | ||
MIN_FOLD_SIZE_HELP = "Minimum number of lines to allow in a foldable range", | ||
SAVE_FOLD_STATES = "Save fold states", | ||
SAVE_FOLD_STATES_HELP = "Save fold states to disk when editor is closed and restore the folds when reopened", | ||
ALWAYS_USE_INDENT_FOLD = "Always use indent fold", | ||
ALWAYS_USE_INDENT_FOLD_HELP = "Fall back to using level of indentation as a folding guideline if no range finder is found for the current mode.", | ||
FADE_FOLD_BUTTONS = "Fade fold buttons", | ||
FADE_FOLD_BUTTONS_HELP = "Hides the fold buttons unless the mouse is over the gutter", | ||
MAX_FOLD_LEVEL = "Max fold level", | ||
MAX_FOLD_LEVEL_HELP = "Used to limit the number of nested folds to find and collapse when View -> Collapse All is called or Alt is held down when collapsing. Should improve performance for large files."; | ||
|
||
//default preference values | ||
prefs.definePreference("enabled", "boolean", true, | ||
{name: strings.ENABLE_CODE_FOLDING, description: strings.ENABLE_CODE_FOLDING}); | ||
{name: ENABLE_CODE_FOLDING, description: ENABLE_CODE_FOLDING}); | ||
prefs.definePreference("minFoldSize", "number", 2, | ||
{name: strings.MIN_FOLD_SIZE, description: strings.MIN_FOLD_SIZE_HELP}); | ||
{name: MIN_FOLD_SIZE, description: MIN_FOLD_SIZE_HELP}); | ||
prefs.definePreference("saveFoldStates", "boolean", true, | ||
{name: strings.SAVE_FOLD_STATES, description: strings.SAVE_FOLD_STATES_HELP}); | ||
prefs.definePreference("alwaysUseIndentFold", "boolean", true, | ||
{name: strings.ALWAYS_USE_INDENT_FOLD, description: strings.ALWAYS_USE_INDENT_FOLD_HELP}); | ||
prefs.definePreference("enableRegionFolding", "boolean", true, | ||
{name: strings.ENABLE_REGION_FOLDING, description: strings.ENABLE_REGION_FOLDING}); | ||
{name: SAVE_FOLD_STATES, description: SAVE_FOLD_STATES_HELP}); | ||
prefs.definePreference("alwaysUseIndentFold", "boolean", false, | ||
{name: ALWAYS_USE_INDENT_FOLD, description: ALWAYS_USE_INDENT_FOLD_HELP}); | ||
prefs.definePreference("fadeFoldButtons", "boolean", false, | ||
{name: strings.FADE_FOLD_BUTTONS, description: strings.FADE_FOLD_BUTTONS_HELP}); | ||
{name: FADE_FOLD_BUTTONS, description: FADE_FOLD_BUTTONS_HELP}); | ||
prefs.definePreference("maxFoldLevel", "number", 2, | ||
{name: strings.MAX_FOLD_LEVEL, description: strings.MAX_FOLD_LEVEL_HELP}); | ||
{name: MAX_FOLD_LEVEL, description: MAX_FOLD_LEVEL_HELP}); | ||
prefs.definePreference("folds", "object", {}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be turned into |
||
|
||
/** | ||
|
@@ -75,8 +83,8 @@ define(function (require, exports, module) { | |
* @return {Object} the line folds for the document at the specified path | ||
*/ | ||
function getFolds(path) { | ||
store = (prefs.get(foldsKey) || {}); | ||
return inflate(store[path]); | ||
var folds = (PreferencesManager.getViewState(foldsKey) || {}); | ||
return inflate(folds[path]); | ||
} | ||
|
||
/** | ||
|
@@ -85,8 +93,9 @@ define(function (require, exports, module) { | |
* @param {Object} folds the fold ranges to save for the current document | ||
*/ | ||
function setFolds(path, folds) { | ||
store[path] = simplify(folds); | ||
prefs.set(foldsKey, store); | ||
var allFolds = PreferencesManager.getViewState(foldsKey); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One other thought... rather than dumping folding state for all files together in one map, it might make sense to bucket it by project, like we do for other similar prefs like the scroll position & selection state of editors. MainViewManager has an example of how to do that:
and
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @peterflynn can you make the || {} change in your PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. brackets/issues/10870 opened to track Code Folding preference minFoldSize and alwaysUseIndentFold require close & reopen of file to take effect. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think using the correct There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @marcelgerber Yep, good point -- that should remove the need for |
||
allFolds[path] = simplify(folds); | ||
PreferencesManager.setViewState(foldsKey, allFolds); | ||
} | ||
|
||
/** | ||
|
@@ -102,7 +111,7 @@ define(function (require, exports, module) { | |
* Clears all the saved line folds for all documents. | ||
*/ | ||
function clearAllFolds() { | ||
prefs.set(foldsKey, {}); | ||
PreferencesManager.setViewState(foldsKey, {}); | ||
} | ||
|
||
module.exports.getFolds = getFolds; | ||
|
@@ -113,4 +122,6 @@ define(function (require, exports, module) { | |
|
||
module.exports.clearAllFolds = clearAllFolds; | ||
|
||
module.exports.prefBase = prefs; | ||
|
||
}); |
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels a little weird -- might be better for these to just be doc comments on the
definePreference()
calls for now... but not a big deal. I think this would be ok to merge as-is.