Skip to content
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

Blockly.FieldNumber does not support HEX #1306

Closed
duzc2 opened this issue Sep 5, 2017 · 5 comments
Closed

Blockly.FieldNumber does not support HEX #1306

duzc2 opened this issue Sep 5, 2017 · 5 comments
Labels
component: fields help wanted External contributions actively solicited issue: feature request Describes a new feature and why it should be added low priority

Comments

@duzc2
Copy link
Contributor

duzc2 commented Sep 5, 2017

I made a optimization to allow use input hex in FieldNumber

Blockly.FieldNumber.prototype.HEXExp = /^0xX+$/g;
/**

  • Ensure that only a number in the correct range may be entered.
  • @param {string} text The user's text.
  • @return {?string} A string representing a valid number, or null if invalid.
    */
    Blockly.FieldNumber.prototype.classValidator = function(text) {
    if (text === null) {
    return null;
    }
    text = String(text);
    // TODO: Handle cases like 'ten', '1.203,14', etc.
    // 'O' is sometimes mistaken for '0' by inexperienced users.
    text = text.replace(/O/ig, '0');
    // Strip out thousands separators.
    text = text.replace(/,/g, '');
    var hex = text.match(Blockly.FieldNumber.prototype.HEXExp);
    var n = hex ? parseInt(text, 16) : parseFloat(text || 0);
    if (isNaN(n)) {
    // Invalid number.
    return null;
    }
    // Round to nearest multiple of precision.
    if (this.precision_ && isFinite(n)) {
    n = Math.round(n / this.precision_) * this.precision_;
    }
    // Get the value in range.
    n = goog.math.clamp(n, this.min_, this.max_);
    return hex ? text : String(n);
    };
duzc2 added a commit to duzc2/blockly that referenced this issue Aug 10, 2019
duzc2 added a commit to duzc2/blockly that referenced this issue Aug 10, 2019
@duzc2
Copy link
Contributor Author

duzc2 commented Aug 10, 2019

oops ,I closed it .... what should I do now ?

@RoboErikG
Copy link
Contributor

I reopened it for you, but your code doesn't do what you think it does. Please test any solutions you have with a variety of inputs to make sure they work.

@RoboErikG
Copy link
Contributor

And just a note for anyone else looking at this, the feature request is to support 3-letter hex color codes. 6-letter hex color codes already work correctly.

@RoboErikG RoboErikG added component: fields help wanted External contributions actively solicited low priority issue: feature request Describes a new feature and why it should be added labels Aug 12, 2019
@duzc2
Copy link
Contributor Author

duzc2 commented Aug 12, 2019

i think this is a number , not a color.
so , 0xfff is not #fff

@RoboErikG
Copy link
Contributor

Oh, you're right. This is the number field you were looking at. Sorry I misunderstood, I was looking at the code in develop instead of master. This was actually fixed by Neil's change to use Number everywhere instead of parseFloat. If you test on develop you'll see '0xff' gets parsed correctly and becomes 255 in FieldNumber.

Closing as this issue is fixed in develop. =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: fields help wanted External contributions actively solicited issue: feature request Describes a new feature and why it should be added low priority
Projects
None yet
Development

No branches or pull requests

2 participants