-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Added smart indent and auto close tags as preferences #6888
Conversation
@@ -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: [] }); |
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.
Typo: indentTabs
should be indentTags
judging by the original code below
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.
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: [] }); |
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'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?
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.
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.
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.
@dangoor Want me to do that instead of using the object?
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.
@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.
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.
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.
I'll do some testing in the morning, but the changes seem fine on the whole. |
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. |
Added smart indent and auto close tags as preferences
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. |
@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. |
Thanks! I don't know what changed since I copied and pasted the exact same text, but somehow it is now working. mysteries |
More Editor preferences to configure using the new Preference System only.