Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Addresses issue #10846 #10850

Merged
merged 3 commits into from
Apr 10, 2015
Merged

Addresses issue #10846 #10850

merged 3 commits into from
Apr 10, 2015

Conversation

thehogfather
Copy link
Contributor

@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

…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,
Copy link
Contributor

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?

Copy link
Contributor

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?

@abose
Copy link
Contributor

abose commented Apr 8, 2015

Code folding is enabled in all files by default, and in some files like txt files it looks a bit odd.
Would it be a good thing to enable code folding in only HTML,XML,js Etc. and disabled in all other file types?

@thehogfather
Copy link
Contributor Author

@abose I suspect the fold marks are appearing in a txt file due to indentations. A suggestion would be to disable the alwaysUseIndentFold option so that only files with registered mode helpers for code-folding have fold markers?

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);
}
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Member

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?

@peterflynn
Copy link
Member

@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 "enabled" preference, but the other preferences still seem to need a restart or close/reopen file to take effect. Did you want to wait for another PR to fix those other prefs?

@peterflynn
Copy link
Member

@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.

@abose
Copy link
Contributor

abose commented Apr 9, 2015

@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
@thehogfather
Copy link
Contributor Author

@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.";
Copy link
Member

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.

@peterflynn
Copy link
Member

Looks like minFoldSize and alwaysUseIndentFold still require close & reopen to take effect. Do you want to spin that off as a separate bug?

@peterflynn
Copy link
Member

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...

@thehogfather
Copy link
Contributor Author

WRT minFoldSize and alwaysUseIndentFold lets file a separate bug with steps to reproduce. When I test it I get the effects immediately within the brackets.json file being edited (after saving).

@@ -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);
Copy link
Member

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.

Copy link
Member

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);

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Member

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();
Copy link
Member

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?

Copy link
Member

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

@peterflynn
Copy link
Member

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.

@peterflynn peterflynn added this to the Release 1.3 milestone Apr 10, 2015
abose added a commit that referenced this pull request Apr 10, 2015
@abose abose merged commit d36f263 into adobe:master Apr 10, 2015
@abose
Copy link
Contributor

abose commented Apr 10, 2015

Loos good now; Merging this PR.
@peterflynn brackets/pull/10859 can now be merged.

@marcelgerber
Copy link
Contributor

@peterflynn It's the same issue for selections/cursors, having two states in one document is weird anyway.

@peterflynn
Copy link
Member

@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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants