CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
#11801 - Restricted Font Size Input To Only Valid Entries #13123
Conversation
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.
just a first quick look without testing, let me know when you'll look at the comments
src/config.json
Outdated
@@ -20,7 +20,7 @@ | |||
"extension_url": "https://s3.amazonaws.com/extend.brackets/{0}/{0}-{1}.zip", | |||
"linting.enabled_by_default": true, | |||
"build_timestamp": "", | |||
"healthDataServerURL": "https://healthdev.brackets.io/healthDataLog" | |||
"healthDataServerURL": "https://health.brackets.io/healthDataLog" |
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 need to revert this change (it applies automatically after doing npm install, but we don't want it in PRs)
src/view/ThemeSettings.js
Outdated
var $target = $(this); | ||
var $input = $target.val(); | ||
var validInput = /^[\d\.]+(p|px|e|em){0,1}$/g; | ||
var btn = document.getElementById("done"); |
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.
add document
to the globals please: https://github.com/adobe/brackets/blob/master/.eslintrc.json#L52
src/htmlContent/themes-settings.html
Outdated
</div> | ||
</div> | ||
</form> | ||
</div> | ||
<div class="modal-footer"> | ||
<button class="dialog-button btn" data-button-id="cancel">{{Strings.CANCEL}}</button> | ||
<button class="dialog-button btn primary" data-button-id="save">{{Strings.DONE}}</button> | ||
<button class="dialog-button btn primary" id="done" data-button-id="save">{{Strings.DONE}}</button> |
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.
id done
is not very good, you should be more specific when introducing id's, something like theme-settings-done-btn
would be more appropriate
src/htmlContent/themes-settings.html
Outdated
</div> | ||
</div> | ||
|
||
<div class="control-group"> | ||
<label class="control-label">{{Strings.FONT_FAMILY}}:</label> | ||
<div class="controls"> | ||
<input type="text" data-target="fontFamily" value="{{settings.fontFamily}}"> | ||
<input type="text" id="font-family-input" data-target="fontFamily" value="{{settings.fontFamily}}"> |
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.
don't need to introduce id's here, you can use .on("input", "[data-target=fontFamily]", function () {
https://www.w3schools.com/jquery/sel_attribute_equal_value.asp
src/view/ThemeSettings.js
Outdated
.on("input", "[data-target]:text", function () { | ||
.on("input", "#font-size-input", function () { | ||
var $target = $(this); | ||
var $input = $target.val(); |
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.
$
prefix for variables indicates that it's a jquery (or a DOM) element
in this case $input
is a string and should really be named input
or even better targetValue
src/view/ThemeSettings.js
Outdated
// Make sure that the font size is expressed in terms we can handle (px or em). If not, 'done' button disabled until input corrected. | ||
|
||
if ($input.search(validInput) === -1) { | ||
($input.length === 0) ? btn.disabled=false : btn.disabled=true; |
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.
btn.disabled = $input.length !== 0
is better
src/view/ThemeSettings.js
Outdated
if ($input.search(validInput) === -1) { | ||
($input.length === 0) ? btn.disabled=false : btn.disabled=true; | ||
return false; | ||
}else{ |
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.
}else{
after return
doesn't make sense, just close the if with }
and continue normally
also make sure command |
.eslintrc.json
Outdated
@@ -57,6 +57,7 @@ | |||
"$": false, | |||
|
|||
"window": false, | |||
"document": false, |
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.
Sorry for mixed signals, but please revert this.
document
is a generic word and in Brackets usually refer to the Document object.
I think you can go with jquery here, can't you? $("#theme-settings-done-btn")
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.
Sorry for the delay--I've been busy with moving, although wanted to finish and reply. That said,, yes, I can use jQuery to avoid going here. Good point. And thanks for clarifying. This is my first pull request; let alone being my first open source patch. I wasn't sure if I should use jQuery as little as possible as noobish as that sounds. This turned out to be a simple fix. :)
Out of curiosity, any reason to not use the pattern attribute? |
Yeah, using pattern ( https://www.w3schools.com/tags/att_input_pattern.asp ) directly on the input would probably be better. |
hello can you contact me mohanad.rahimi1@gmail.com |
…ibute, jQuery for var $btn, etc.
Thanks, guys, for your speedy replies. And the link. To reply now to @ficristo: that HTML5 pattern attribute was actually wholly new to me. I've learned and relearned a bunch of neat stuff here in just a few reviewer comments. And I have to agree with you both that "pattern" is much better in usage. Thanks again! Please feel free to let me know if anything else would be problematic. |
fine with me, @ficristo ? |
It seems fine for me. brackets/src/view/ViewCommandHandlers.js Line 300 in d6ae906
and use it on the html. |
@nyteksf to do what @ficristo wrote, you'd have to edit this file https://github.com/nyteksf/brackets/blob/9a6f12cf259276ebd163e70266030377df67eb2b/src/view/ViewCommandHandlers.js and make this brackets/src/view/ViewCommandHandlers.js Line 300 in d6ae906
Then here https://github.com/nyteksf/brackets/blob/9a6f12cf259276ebd163e70266030377df67eb2b/src/view/ThemeSettings.js#L82 you'd pass the Hope that's clear enough, @ficristo correct me if I'm wrong |
LGTM, but we should accept at least |
Current regexp which is used deeper ( brackets/src/view/ViewCommandHandlers.js Line 300 in d6ae906
px|em ... do we want to change this?
|
Thank you, guys. I have had to fiddle around with the RegExp a little to make the prescribed changes work. It seems backslashes need to be escaped to be exported successfully with mustache--having tried the various remedies in the docs that seemed to apply--and this causes the RegExp constructor used for the non-exported segment to be passed something unintended in that case (e.g., That said, rather than attempting to escape any characters, I have switched the RegExp in question to |
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.
just a few small changes that are of stylistic nature and I believe we're good to merge this
src/htmlContent/themes-settings.html
Outdated
@@ -30,7 +30,7 @@ <h1 class="dialog-title">{{Strings.THEMES_SETTINGS}}</h1> | |||
<div class="control-group"> | |||
<label class="control-label">{{Strings.FONT_SIZE}}:</label> | |||
<div class="controls"> | |||
<input type="text" data-target="fontSize" value="{{settings.fontSize}}"> | |||
<input type="text" pattern="{{ settings.validFontSizeRegExp}}" data-target="fontSize" value="{{settings.fontSize}}"> |
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.
missing space before }}
src/view/ThemeSettings.js
Outdated
return result; | ||
} | ||
|
||
var validFontSizeRegExp = ViewCommandHandlers.validFontSizeRegExp; |
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.
constant definitions should always be on top of the file after imports, or you can use ViewCommandHandlers.validFontSizeRegExp
directly
src/view/ThemeSettings.js
Outdated
@@ -81,7 +82,7 @@ define(function (require, exports, module) { | |||
var template = $("<div>").append($settings).html(); | |||
var $template = $(Mustache.render(template, {"settings": currentSettings, "themes": themes, "Strings": Strings})); | |||
|
|||
// Select the correct theme. | |||
// Select the correct theme. |
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.
invalid whitespace change
src/view/ViewCommandHandlers.js
Outdated
|
||
// Make sure that the font size is expressed in terms we can handle (px or em). If not, simply bail. | ||
if (fsStyle.search(validFont) === -1) { | ||
var validFontSizeRegExpStr = "^[0-9.]+(px|em)$"; // Need RegExp string to be exported for compatibility with HTML5 pattern attribute. |
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.
constant definitions should always be on top (after import declarations) and not between functions, also needs a comment, something like:
/*
* Font sizes should be validated by this regexp
*/
Whoops! Well, okay: there you go. Thanks again for a speedy reply! |
Testing this, it allows input like: |
Done with testing, just change this one and I'm merging this (promise 😄 ) |
Okay. I'm going out on a limb here: so of course please do correct me if my suggestion happens to be wrong. I added your change to the original deeper RegExp. Then in doing my own testing, I had found that by comparison to the original it worked almost perfectly. That RegExp in question, however, didn't handle cases like " |
Nevermind. I found a flaw with my last change. I am re-changing the RegExp to address cases like " |
Okay, @zaggino. My fingers are crossed this time. I'm sending my final changes over your way if you'll please take another look now. :) |
Oh, github new features are superb, did a small change to your regexp through the web - when inside a string you need to escape |
Looks good to me now. I think all comments above have been considered so I'm merging this. |
Related to #11801.
Text was able to be inputted into Font Size within Themes Settings (e.g. "View > Themes...") even when it included non-ASCII characters or was in a generally unusable format.
Corrected this issue by ensuring all font sizes are to begin with a number, and are completed by either "px" or "em" only. 'Done' button remains disabled until said format is adhered to correctly--at which time the functionality of said button becomes restored allowing input to be saved.
@zaggino