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

Added smart indent and auto close tags as preferences #6888

Merged
merged 2 commits into from
Feb 20, 2014

Conversation

TomMalbran
Copy link
Contributor

More Editor preferences to configure using the new Preference System only.

@@ -101,9 +106,10 @@ define(function (require, exports, module) {
PreferencesManager.definePreference(SHOW_LINE_NUMBERS, "boolean", true);
PreferencesManager.definePreference(STYLE_ACTIVE_LINE, "boolean", false);
PreferencesManager.definePreference(WORD_WRAP, "boolean", true);
PreferencesManager.definePreference(CLOSE_TAGS, "Object", { whenOpening: true, whenClosing: true, indentTabs: [] });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: indentTabs should be indentTags judging by the original code below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woops. Will fix that

@@ -101,9 +106,10 @@ define(function (require, exports, module) {
PreferencesManager.definePreference(SHOW_LINE_NUMBERS, "boolean", true);
PreferencesManager.definePreference(STYLE_ACTIVE_LINE, "boolean", false);
PreferencesManager.definePreference(WORD_WRAP, "boolean", true);
PreferencesManager.definePreference(CLOSE_TAGS, "Object", { whenOpening: true, whenClosing: true, indentTags: [] });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little uncertain about having this be an object pref vs. a boolean or some combination of other prefs. It makes this a bit more complex to use. That said, I looked at closetag.js and seeing how these options work, I can imagine people reasonably wanting to tweak these different values.

Aside: I wonder why we override indentTags?

One possibility is to start with just a closeTags boolean that's either all on (the definition above) or all off and then define other (less likely to be used) preferences to customize the behavior further. I could imagine indentTags being a separate pref, for example.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially I just wanted to add whenOpening and whenClosing as boolean prefs, since those are the useful ones. People would like to disable one but not both and other disable both. But I wasn't sure how it would work when updating the preference in CodeMirror. I guess if I go that way it would require a special case to handle it.

So I am ok in using 2 boolean pref and a special case to handle the on change event.

We overwrite indentTags because if we don't then when you have <div| and write a > it auto-completes and indents the tag becoming:

<div>
    |
</div>

Which is really annoying, but some people might like it. So you can define for which tags this behavior is ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dangoor Want me to do that instead of using the object?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TomMalbran Sorry I didn't get back to this earlier. Given your description, I'd say we can just leave it as an object. We may make some changes when we do the UI, but I don't think it's worth adding a bunch of special case code at this point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem. Just trying to make sure to get this into Release 37 :)

I guess the UI might be a problem. A simple UI where we just edit a JavaScript Object with lots of comments and all the possible preference would just work fine. A more complex ones with inputs should have some sort of API where each module can add new input lines for each preference to add to the UI, and that API could handle inputs as objects.

@dangoor
Copy link
Contributor

dangoor commented Feb 20, 2014

I'll do some testing in the morning, but the changes seem fine on the whole.

@dangoor
Copy link
Contributor

dangoor commented Feb 20, 2014

Funny. I thought that the settings were behaving funny with HTML files and then I realized that Emmet was controlling those settings.

Looks good. Merging.

dangoor added a commit that referenced this pull request Feb 20, 2014
Added smart indent and auto close tags as preferences
@dangoor dangoor merged commit faa5454 into master Feb 20, 2014
@dangoor dangoor deleted the tom/new-editor-prefs branch February 20, 2014 16:48
@berriganator
Copy link

I cannot seem to get the .json syntax correct to turn the auto indentation off. It's driving me nuts. Can you please write a better guide for those of us unaccustomed to editing .json files to control these features? The samples given in the Wiki are not straightforward to newbies. Thanks.

@redmunds
Copy link
Contributor

@berriganator There's an extension called "JSONLint" that will tell you if you have any syntax errors in a .json file. Works great!

There's also a "Brackets Preferences" extension that provides a UI for preferences, but it's very early in development, so I'm not sure how well it works.

@berriganator
Copy link

Thanks! I don't know what changed since I copied and pasted the exact same text, but somehow it is now working. mysteries

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.

5 participants