-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Conversation
…wState (state.json) Added copyright text into foldcode.js and foldgutter.js Removed strings.js file Removed latex-fold helper Removed menu item for custom region folding Disable custom region folding by default
@@ -23,7 +22,7 @@ define(function (require, exports, module) { | |||
{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, | |||
prefs.definePreference("enableRegionFolding", "boolean", false, |
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.
If we do not expose the region fold feature by default, should we include it in the view menu?
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.
Ok got it. The custom region folds feature is being removed. In that case, could't we remove the preference entry altogether, along with the menu entry and the corresponding strings?
Code folding is enabled in all files by default, and in some files like txt files it looks a bit odd. |
@abose I suspect the fold marks are appearing in a txt file due to indentations. A suggestion would be to disable the |
Set alwaysUseIndentFold preference to be false by default Addresses adobe#10848 - changes to preference files are now updated live in brackets without needing to restart
if (editor && editor._codeMirror && CodeMirror.commands.unfoldAll) { | ||
CodeMirror.commands.unfoldAll(editor._codeMirror); | ||
foldGutter.remove(editor._codeMirror); | ||
} |
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.
Wouldn't you need to do this for all existing Editor instances, not just the current one?
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.
Yes we would. Currently the other editors open 'catch up' when the active editor changes. I couldn't find an api for iterating through open editors in the working set. Is there one? How would you do it?
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.
It will definitely look bad for split view, where two editors are visible at once even though only one is active.
The cleanest way to do it is walking the _instances
array in Editor.js, which is currently inaccessible -- that's how core Editor preferences are updated. It seems fair to me to add a public API like forEveryEditor()
or something -- pass a callback, and it gets invoked like a forEach.
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.
It might be easier for me to take care of this issue in my PR -- that ok with you?
@thehogfather This looks great overall, thanks for posting this update so quickly! I added a few comments above. One other note: this fixes bug #10848 for the |
@thehogfather Fyi, I've opened PR #10859 with some UI changes as well as a few code tweaks. Some of it duplicates change you've made here (I started working on it before you posted this), so once your PR is merged I'll rebase mine on top of your changes. But please take a look and see if there's anything else there you'd be concerned about. |
@thehogfather Now that custom region fold support is removed, fold helper - region-fold.js could also be removed. |
Changes to all preferences are now live Removed region-fold and custom-region fold strings
@abose @peterflynn I think this should be closer to ready than before. Cleaned up the strings and removed custom-region folding completely. Now over to you. Happy to help with anything else you direct my way. |
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."; |
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.
Looks like |
Hmm, it also looks like folds are no longer remembered when you close & reopen a file, even with a completely clean slate of prefs. Seems like something is broken with the view-state storage changes here... |
WRT |
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
You need || {}
here too -- that's why saving folds is broken currently.
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.
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:
context = { location : { scope: "user",
layer: "project" } },
state = PreferencesManager.getViewState(PREFS_NAME, context);
and
context = { location : { scope: "user",
layer: "project",
layerID: projectRoot.fullPath } },
...
PreferencesManager.setViewState(PREFS_NAME, state, context);
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.
@peterflynn can you make the || {} change in your PR?
Also issues#10869 added for tracking the bucketing by project.
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
I think using the correct PreferencesManager.stateManager.definePreference(...
will fix that, won't it?
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.
@marcelgerber Yep, good point -- that should remove the need for || {}
both here & in getFolds()
.
@@ -317,29 +416,12 @@ define(function (require, exports, module) { | |||
init(); |
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.
Btw, why do we need to call init()
again on project open? Now that we're listening for preference changes at all times, it seems like this should be unnecessary?
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.
I removed this in my PR and things still seem to work ok
Btw, it's still a ways off but it will be interesting to think about what having the same document visible in two split panes will mean for code folding. Should collapsing a section in one pane automatically collapse it in the other? Seems like that would feel weird, but otoh if each editor has its own expand/collapse state for the same document, how will that be persisted? Which one "wins" if you close both views? Etc. I'll add a note to that Trello story so we can think about it more when the time comes. |
Loos good now; Merging this PR. |
@peterflynn It's the same issue for selections/cursors, having two states in one document is weird anyway. |
@abose Wait, why did you merge this already? See my comments above -- #10850 (comment) and #10850 (comment) -- code folding persistence is completely broken in master now because of this PR. We should have waited before fixing that blocker before merging... I'll file a high-priority bug to track it. |
@abose @peterflynn (apologies it isn't solely related to #10846 - it felt sensible to combine into one PR)
Fold states are now persisted using viewState (state.json)
Added copyright text into foldcode.js and foldgutter.js
Removed strings.js file
Removed latex-fold helper
Removed menu item for custom region folding
Disable custom region folding by default