-
Notifications
You must be signed in to change notification settings - Fork 284
Added all components for Border Radius Inline editor #890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Hey, awesome - this is super cool @feihaozi77 👍 Some thoughts...
So when you type anything, it replaces the selection immediately. Anyway, this is great - really excited to see this progress 💯 Of course, I'll take care of all the styling and UI once the functionality is getting closer to our final version. |
|
@flukeout Sure I'll work on the parts you mentioned. |
|
@flukeout made some changes |
|
Thanks for your patience @feihaozi77 - reviewing again now. |
|
This is getting really good! Here is some more feedback...
I'm imagining a way where the
Does it make sense? Let me know! Thanks so far!! |
…fecting each other
|
@flukeout I made the changes you need to seperate the allCornerSlider and the individualSlider, please review when you are avaliable |
|
Awesome, will try it out now. |
|
OK, great! I think that works much better. Some more requests: Request 1
I think it would be good to show the icon right then so they could start using the UI right away if they wanted to. Request 2
Once we get these changes in I can make a PR against your branch with styling updates, etc. 👍 |
|
@flukeout let me clarify request1, do you mean you want the purple icon to pop up automatically without user clicking the text when user finished typing something like border-radius: |
|
@flukeout I think I'll get your request 2 done by tomorrow but the 1st request seems pretty hard, I've been stucking there for awhile, I looked into the PopoverWidget.js file, the positionPopover function is being called, if I set a break point inside the positionPopover function, the bubble was showed at first when the execution was stopping at the break point, but once I step over the break point the bubble just dispeared. I could not figure out this, maybe some one who are more familliar with codemirror could help |
|
Hey @feihaozi77 - yeah with regard to Request 1 - that's what I had in mind. If it's proving too time consuming, let's not worry about it too much at this point. We could always try to solve it with another effort down the road. |
|
@flukeout request2 completed |
|
Awesome @feihaozi77 - will take a look a little later today! |
|
Looking now. |
|
This is great @feihaozi77! I've got a question: is it possible for the UI to be aware of the units used in the rule? For example, if I have Then, on top of that, maybe we should add a toggle to each value that lets the user choose then unit. Something like this...
Let me know if that is possible. Thanks! |
|
@flukeout regarding your request "if I have border-radius: 5px 10%; and open the UI, it converts all of the units to px. Is it possible to keep %?", should be able to do that. not sure about the toggle part yet. |
|
@flukeout Added the part for keeping %, em and px units |
|
Testing now @feihaozi77 - thanks! |
|
Hey @feihaozi77, when opening a single-value border-radius, is it possible to also populate that value into all of the corner values? See the screencap below, when I open it, all of the values are set to 0... |
|
@flukeout sure, I will work on that, and right now i'm trying to add the radio buttons for each of the corners to toggle their units |
|
Ooops, sorry accidentally closed and opened. Awesome, thanks for the update, looking forward to it! |
|
@humphd ready for review again |
src/brackets.js
Outdated
| require("utils/Resizer"); | ||
| require("LiveDevelopment/main"); | ||
| require("utils/ColorUtils"); | ||
| require("utils/BorderRadiusUtils"); |
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 shouldn't need to require() a file needed by an extension in the core. Can you not move this into your main.js or the extension?
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.
@humphd Should I remove this line from the brackets.js file?
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.
Yeah, I think so. The only reason to have it here is if you have to have it loaded early for some reason so that other code can access it, and it has to do some kind of initialization. In your case, you should just load it when you need it, where you need 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.
In the brackets.js, the colorUtil.js file is also being requried(), That's why I put the borderRadiusUtil.js in here. And I noticed that, if I remove the borderRadiusUtil.js file away from bracket.js, then the BorderRadiusUtil.js will not be loaded in the browser. So basically, if I remove the file from brackets.js, then in my extension, for instance, the InlineBorderRadius.js will not get the BorderRadiusUtils.js because it is using something like this " brackets.getModule("utils/BorderRadiusUtils"); " to load the util 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.
Both require() and brackets.getModule() do the same thing, namely, they load a module. However, you use one or the other depending on where the module is defined. For example, in the core of Brackets, you always use require(). In an extension, you use require() when the module you are loading is defined within the extension. However, if you need to load a core module in an extension, you use brackets.getModule().
If you only need this file in your extension code, which you do, you can just use require() in the extension code before it is used.
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 got it thank you, so I think instead of using brackets.getModule, I should use require() to do the samething in my extension files, because I'm only getting reference to that one file , it's not nessasary to put the file in the core module. is this correct?
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 got it. Let me know if you need help getting it to load properly--sometimes there can be dependency load-order issues with require.
| /** Mustache template that forms the bare DOM structure of the UI */ | ||
| var BorderRadiusTemplate = require("text!BorderRadiusEditorTemplate.html"); | ||
| var DEFAULT_BORDER_RADIUS_VALUE = 0; | ||
| /** |
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 comment doesn't seem to match what's happening in the function
| * @param {!{horizontalOffset: string, verticalOffset: string, blurRadius: string, spreadRadius: string, color: string}} values Initial set of box-shadow values. | ||
| * @param {!function(string)} callback Called whenever values change | ||
| */ | ||
| function replaceAll(value,str1,str2,ignore){ |
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 feel like this is named well. You have a much more complex regex in here than just replacing one string in another. Can you add a comment to explain the regex, and what it's looking for, and also what this really does?
| } | ||
|
|
||
| /** | ||
| * A string or tinycolor object representing the currently selected color |
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 still hasn't been addressed.
|
|
||
| BorderRadiusEditor.prototype._setInputValues = function(setFromString) { | ||
| var values = this.individualValuesWithUnit; | ||
| if(!this._allCorners){ |
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 code is all indented too far.
|
|
||
| }; | ||
| BorderRadiusEditor.prototype.setRadioButtons = function(values){ | ||
| //when initializing |
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.
Indented too far.
| BorderRadiusEditor.prototype.updateRadios=function(corner,unit){ | ||
| if(corner==="tl"){ | ||
| if(unit==="percent"){ | ||
|
|
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.
Remove this line
| result+=_array[i]; | ||
| } | ||
| this._values = result; | ||
| this._callback(value); |
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.
Does this mean you'll call the callback more than once, since _commitChanges is called more than once above? If so, is that expected? It's an odd pattern: usually you'd just call a callback once, and if you need to call it many times, you'd do some kind of event handler instead.
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.
@humphd In this case, the event handler is being implemented in the InlineBorderRadiusEditor.js layer, whenever the UI element(slider) changes, it will trigger the event handler in BorderRadiusEditor.js, then BorderRadiusEditor.js will update the UI and then send control back to InlineBoderRadiusEditor.js by calling the _callback(), which is mapping to the _handleBorderRadiusChange() in the InlineBorderRadius.js. the _handleBorderRadiusChange() will be updating document text.
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.
@humphd basically, in my code, the InlineBorderRadiusEditor.js handles the Document updating tasks while BorderRadiusEditor.js handles UI Updating first then send control to InlineBorderRadiusEditor.js to update the Text in the hostEditor.
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.
@humphd I'm not really sure how to implement the event handler for the _callback, since BorderRadiusEditor and InlineBorderRadiusEditor works on different layers, could you give more hint on this? or maybe we can discuss about this in class tomorrow.
| <header> | ||
| <ul class="button-bar"> | ||
| <li id="allCorners" title="All Corners"> | ||
| <a href="#" tabindex="0">All Corners</a> |
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'll need to localize all user visible strings.
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.
| @@ -0,0 +1,412 @@ | |||
| @sansFontFamily: "Open Sans" , Helvetica, Arial, sans-serif; | |||
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 need to confirm with @flukeout the font choice here so it matches what we use elsewhere.
src/brackets.js
Outdated
| require("utils/Resizer"); | ||
| require("LiveDevelopment/main"); | ||
| require("utils/ColorUtils"); | ||
| //require("utils/BorderRadiusUtils"); |
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.
Remove this
| return parsedResult; | ||
| } | ||
|
|
||
| function BorderRadiusEditor($parent, values, callback) { |
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.
Rename callback to indicate that it's a handler
|
@humphd @gideonthomas I made a Pull Request to the thimble repo for adding the localized strings to the locales folder in thimble repe. Please take a look and let me know if that's OK. Here is the PR link mozilla/thimble.mozilla.org#2585 |
|
@humphd @gideonthomas ready for review! |
|
@feihaozi77, sorry about the delayed response...I haven't forgotten about your PR. Since this is a pretty big code change, I'm going to open a PR against your branch that you can merge in with changes that I suggest. |
gideonthomas
left a comment
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.
Hi @feihaozi77, I have opened up a PR against your branch as you can see in feihaozi77#3. Please read the comment there.
|
@gideonthomas I have merged your branch. Good work!! I like the idea that you implement the BorderRadiusValue class which makes the code much cleaner and reusable. Thank you very much!! |
gideonthomas
left a comment
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.
added a few more comments @feihaozi77
|
|
||
| this.allCorners = values.length === 1; | ||
|
|
||
| if (!this.allCorners) { |
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 noticed another bug. Change this entire if into:
if (!this.allCorners) {
secondValue = values[1];
if (numOfValues === 2) {
fourthValue = secondValue;
} else {
thirdValue = values[2];
if (numOfValues === 3) {
fourthValue = secondValue;
} else {
fourthValue = values[3];
}
}
}| secondValue.unit, | ||
| this.onChange | ||
| ); | ||
| this.bottomLeft = new BorderRadiusValue( |
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 needs to be this.bottomRight
| ); | ||
| this.bottomLeft = new BorderRadiusValue( | ||
| this.$element, | ||
| "bottom-left", |
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.
needs to be "bottom-right"
| thirdValue.unit, | ||
| this.onChange | ||
| ); | ||
| this.bottomRight = new BorderRadiusValue( |
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 should be this.bottomLeft
| ); | ||
| this.bottomRight = new BorderRadiusValue( | ||
| this.$element, | ||
| "bottom-right", |
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.
change this to bottom-left
| /** @type {boolean} True while we're syncing a color picker change into the code editor */ | ||
| InlineBorderRadiusEditor.prototype._isOwnChange = null; | ||
|
|
||
| /** @type {boolean} True while we're syncing a code editor change into the color picker */ |
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.
update this comment
|
|
||
|
|
||
| /** | ||
| * Returns the current text range of the color we're attached to, or null if |
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.
update this comment
| } | ||
| } | ||
|
|
||
| function queryInlineBorderRadiusEditorPrivoder(hostEditor, pos) { |
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
|
|
||
| // Initialize extension | ||
| ExtensionUtils.loadStyleSheet(module, "css/main.less"); | ||
| EditorManager.registerInlineEditProvider(inlineBorderRadiusEditorProvider, queryInlineBorderRadiusEditorPrivoder); |
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
| return true; | ||
| } | ||
|
|
||
| // Get the css property name after removing spaces and ":" so that we can check for it in the file ColorProperties.json |
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.
update this comment
|
@gideonthomas changes are made! |
gideonthomas
left a comment
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.
needs one more indentation change, otherwise this is good to go.
| secondValue = values[1]; | ||
|
|
||
| if (numOfValues === 2) { | ||
| fourthValue = secondValue; |
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.
fix the indentation here. Needs to be 4 spaces.
|
Thanks for making the changes @feihaozi77, this looks good now! |




Added all components for inlineBorderRadiusEditor