-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Conversation
|
||
|
||
/** | ||
* @private (but might be useful in a Validation module) |
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.
These aren't private any more.
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.
Fixed.
I think the validation should be done in the PreferencesManager. Something like this: PreferencesManager.definePreference(SPACE_UNITS, "number", DEFAULT_SPACE_UNITS, {
validator: function (value) {
return ValidationUtils.isIntegerInRange(value, 0, null)
}
}); Then What do you think of that approach? |
I like the validator approach -- nice suggestion! I'll implement that. |
Changes pushed. Ready for another review. |
@@ -37,6 +37,7 @@ define(function (require, exports, module) { | |||
var CodeInspection = brackets.getModule("language/CodeInspection"), | |||
PreferencesManager = brackets.getModule("preferences/PreferencesManager"), | |||
Strings = brackets.getModule("strings"), | |||
ValidationUtils = brackets.getModule("utils/ValidationUtils"), |
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.
Not required anymore
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.
Good catch! Fixed.
@TomMalbran Thanks for the review. Changes pushed. |
}); | ||
PreferencesManager.definePreference(SPACE_UNITS, "number", DEFAULT_SPACE_UNITS, { | ||
validator: function (value) { | ||
return ValidationUtils.isIntegerInRange(value, 0, null); |
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.
In https://github.com/adobe/brackets/blob/randy/issue-7020/src/editor/EditorStatusBar.js#L134 we make the value be between 1 and 10 for both preferences. Should we make 10 the max here too? And should we fix the min there so that it can be 0 for space units? Once we do that, the min and max values should be exported constants so that we can use them in EditorStatusBar.
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.
Ah, I forgot about that code! I agree that these should be consistent and I'll define a constant.
I thought @RaymondLim said that 0 is valid for space units, so that's why it's allowed.
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 don't mean changing the 0 value here, but allow the user to set it to 0 when changing it in the Status Bar.
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, that's what I did.
@TomMalbran Pushed more changes. |
@@ -88,7 +88,7 @@ define(function (require, exports, module) { | |||
|
|||
if (!options.indent) { | |||
// default to using the same indentation value that the editor is using | |||
options.indent = PreferencesManager.get("spaceUnits"); | |||
options.indent = PreferencesManager.get("spaceUnits", fullPath); |
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.
Any reason why we don't use editor.getSpaceUnits
here?
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.
We don't have an Editor instance.
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 see. I guess is fine then.
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.
Nice change! At first, I figured this wasn't required, but since we have the path in hand, we're better off using it. That makes this function potentially usable for mass linting independent of the current editor.
The code looks good to me now. |
I'm seeing a should find preferences in the project
|
@redmunds You may need to adjust the value in test file |
Changes pushed. Ready for another review. |
@redmunds I started a bit on UI and will put together a PR once this is merged so I can include validator strings in that |
var valInt = parseInt(value, 10); | ||
if (editor.getUseTabChar()) { | ||
if (!editor.setTabSize(valInt)) { | ||
return; // validation failed |
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.
false
does not necessarily mean that validation failed. It just means that the value wasn't set. Should we differentiate? I think we can still change the PreferencesSystem.set
API at this point because nothing in Brackets relies on that return value, and I'd be surprised if extensions used that yet. In fact, your use here is the first use I've seen of the set
return value.
With the API as it stands now, a false
return value means that the caller will have to call a separate function to find out if the given value is valid.
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.
We could easily differentiate. How about returning an object like:
{
valid: {boolean},
stored: {boolean}
}
Error message would be added at a later time.
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 would be a good time to change it, since that API is unused and the change is simple. Your suggestion seems good to me.
I'm fine with punting on the extra validation features for now. We'll need to address them as soon as we have a preferences UI, but not necessarily before then. |
@redmunds The difference is that factories lead to more succinct and scannable code, with less boilerplate to clutter things. Compare:
vs.
(And the difference could potentially get larger once error strings are introduced). |
I think you shouldn't remove
for a factory. |
Cool, Thanks. |
@peterflynn Seems like the only difference is where the function gets created. I kind of like the idea of a ValidationUtils module that would just provide some basic functions that could be used for any kind of validation, so I'm leaning towards keeping it like it is. |
@redmunds The difference is how many times the function gets created -- the more verbose way adds 3 extra lines of code (or more) per preference. The factory idea only writes out the method body once, within the central utils module. I think we should still keep the basic functions, but factory wrappers would simplify the code in 90% of cases... |
@dangoor Changes pushed. |
The validation is okay as it is, and we can optimize more as we see how this usage grows. The functional approach for shortening this would be: @redmunds One last question: should the |
Nice. Done.
I'm having seconds thoughts about this API. What if we keep it |
@dangoor I made the API changes that we discussed. Ready for another review. |
var current = EditorManager.getActiveEditor(), | ||
fullPath = current && current.document.file.fullPath; | ||
|
||
Editor.setUseTabChar(!Editor.getUseTabChar(fullPath), fullPath); |
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 is fine and explicit, but to some extent it is redundant because PreferencesManager.get("useTabChar") not qualified by a file will default to the currently edited file.
Looks good. Merging. |
This is for #7020.
I did a slight refactoring so editor prefs can be validated when ever they change. Currently only validate "tabSize" and "spaceUnits" which are numbers. All other prefs are boolean, so the only thing validation would do is to enforce default if user mucks up the prefs file.
I started a
ValidationUtils
module that might be useful in other places.