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

comma separated lists not updated properly #562

Closed
intentionally-left-nil opened this issue Aug 4, 2015 · 1 comment
Closed

comma separated lists not updated properly #562

intentionally-left-nil opened this issue Aug 4, 2015 · 1 comment

Comments

@intentionally-left-nil
Copy link
Contributor

Repro example:
http://jsfiddle.net/65xCP/138/

The bug is in the Hooks.injectValue function. Specifically, CSS.RegEx.valueSplit converts #ff0000 -2px 0px 0px 0px, #00ff00 2px 0px 0px 0px into the wrong pieces. The code just needs to apply the same action to every item in the list. I've created the following replacement function which works for our needs, feel free to use it as you will. If you want I can tidy it up into a PR, but your documentation says not to :-). Also the fact that line endings are ^M instead of \n make it much more difficult to work in the codebase and lastly it would be great if you could hook up package.json such that npm test works. Thanks!

P.S. the regex is needed to capture the case of rgb(0,0,0) 0px 0px 0px, . It is just looking for a comma outside of parens(). I am not sure if there is any other valid CSS that can have commas in them, but they would also need to be detected with the regex.

injectValue: function (fullHookName, hookValue, rootPropertyValue) {
    var hookData = CSS.Hooks.registered[fullHookName];

    if (hookData) {
        var hookRoot = hookData[0],
            hookPosition = hookData[1],
            rootPropertyValueParts,
            rootPropertyValueUpdated;

        rootPropertyValue = CSS.Hooks.cleanRootPropertyValue(hookRoot, rootPropertyValue);
        rootPropertyValueUpdated = rootPropertyValue.split(/, +(?![^(]*?\))/g).map(function(item) {
            /* Split rootPropertyValue into its individual hook values, replace the targeted value with hookValue,
               then reconstruct the rootPropertyValue string. */
            rootPropertyValueParts = item.toString().match(CSS.RegEx.valueSplit);
            rootPropertyValueParts[hookPosition] = hookValue;
            return rootPropertyValueParts.join(" ");
        }).join(', ');

        return rootPropertyValueUpdated;
    } else {
        /* If the provided fullHookName isn't a registered hook, return the rootPropertyValue that was passed in. */
        return rootPropertyValue;
    }
}
@Rycochet
Copy link
Collaborator

Rycochet commented Aug 5, 2015

You can set git itself to change line endings on pull and push ;-)

From what I remember you also have the background style like this - linear gradient(keywords, color number%, color number%, ...), another background using a different format, etc....

Box-shadow can have the argument order in multiple ways which all. I always put the color at the end as recommended by MDN - and chrome always puts the colour at the start.

Perhaps there should be a colour only version of this that finds rgb/rgba/# values for adjusting?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants