Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Return the css property value range in getInfoAtPos() api.#7390

Merged
JeffryBooher merged 10 commits intomasterfrom
rlim/range-in-css-info
Apr 5, 2014
Merged

Return the css property value range in getInfoAtPos() api.#7390
JeffryBooher merged 10 commits intomasterfrom
rlim/range-in-css-info

Conversation

@RaymondLim
Copy link
Copy Markdown
Contributor

This is required for CSS Shapes Editor to handle CSS property values spanning over multiple lines.

@JeffryBooher and @oslego Can you review this?

@RaymondLim
Copy link
Copy Markdown
Contributor Author

@JeffryBooher I'm done fixing unit tests. Ready for you to land in master. I reviewed yours already. Thanks.

Comment thread test/spec/CSSUtils-test.js Outdated
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: currect

Comment thread src/language/CSSUtils.js Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the conditional? can't isNewItem just just be assigned to the argument coming in? you could do isNewItem: (isNewItem === true) which is more performant since it's just a simple math eval

@JeffryBooher
Copy link
Copy Markdown
Contributor

Done with review. @RaymondLim let me know when you're ready for me to merge

@RaymondLim
Copy link
Copy Markdown
Contributor Author

@JeffryBooher Changes are pushed. Ready for re-review.

Comment thread src/language/CSSUtils.js Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this might be better while (TokenUtils.moveNextToken(startCtx) && !startCtx.token.string.trim()); but I'm not sure if crockford will like it.

another thing that i'm wondering if TokenUtils.moveNextToken() returns false then we fall through and we're using the property name as the thing returned. Perhaps that needs a unit test in the case of a malformed property at the end of the file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, linter will complain on the empty block. And you're mistaken with the direction. We're scanning forwards and not backwards here.

@JeffryBooher
Copy link
Copy Markdown
Contributor

Looks good. Unit tests pass. Review Complete all comments addressed. Merging

JeffryBooher added a commit that referenced this pull request Apr 5, 2014
Return the css property value range in getInfoAtPos() api.
@JeffryBooher JeffryBooher merged commit 31dee88 into master Apr 5, 2014
@JeffryBooher JeffryBooher deleted the rlim/range-in-css-info branch April 5, 2014 06:22
Comment thread src/language/CSSUtils.js
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JeffryBooher @RaymondLim I know this is already merged, but you should never use trim() in a condition. It unnecessarily creates a new string. Instead, use:

    if (startCtx.token.string.search(/\S/)) {

This detects the presence of a non-whitespace character.

@JeffryBooher
Copy link
Copy Markdown
Contributor

@redmunds that's a good point about unnecessarily creating a new string but we aren't searching for the presence of whitespace, we're effectively looking for a string that is empty after removing all whitespace ...

@redmunds
Copy link
Copy Markdown
Contributor

redmunds commented Apr 7, 2014

@JeffryBooher I believe that is the same thing -- let me know if you can think of any case that this doesn't work for.

@JeffryBooher
Copy link
Copy Markdown
Contributor

@redmunds I think you could match on this: /[^\S]/ to search for any non-whitespace

@redmunds
Copy link
Copy Markdown
Contributor

redmunds commented Apr 7, 2014

@JeffryBooher \s (lowercase) is for whitespace and \S (uppercase) is for the opposite (i.e. non-whitespace).

@JeffryBooher
Copy link
Copy Markdown
Contributor

I guess on an iPhone it's hard to tell the difference :)

@RaymondLim
Copy link
Copy Markdown
Contributor Author

@redmunds I'll submit a pull request to clean up all the usage of trim() for this purpose. I prefer to use string.match(/\S/) instead of string.search(/\S/) since we don't really need to know the position. See this http://jsperf.com/exec-vs-match-vs-test-vs-search/5 for a comparison.

@redmunds
Copy link
Copy Markdown
Contributor

redmunds commented Apr 7, 2014

@RaymondLim According to that chart, it looks like /\S/.test(string) is even faster.

@RaymondLim
Copy link
Copy Markdown
Contributor Author

You're right! I was interpreting the opposite.

@JeffryBooher
Copy link
Copy Markdown
Contributor

@RaymondLim, I'm already working on a pull request

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants