Limit QuickView to literal color names in some languages #8156

Merged
merged 8 commits into from Sep 4, 2014

Projects

None yet

3 participants

@MarcelGerber
Member

For #6836.
Limits QuickView to only literal color names in JS (including JSON), PHP and CoffeeScript.
Includes Unit tests and one new test file.

@peterflynn
Member

I wonder if we should go further and switch to a whitelist -- respecting named colors only in CSS/LESS/SCSS files. I sometimes get the popover on words when editing plain .txt files, for example...

@MarcelGerber
Member

On words, you'll still get a popover (right now). It's currently only disabled for object/array keys and functions.

@redmunds
Contributor

Definitely want something along these lines. Triage Complete.

@redmunds
Contributor

@dangoor @SAPlayer After a closer look, I'm concerned about performance. Currently, a fair amount of Quick View processing is done during mousemove event processing and this adds a lot parsing using CodeMirror tokenizer. I don't think this pull request should be merged until the Defer most Quick View processing until after delay pull request has been merged.

@MarcelGerber
Member

@redmunds That's ok. But btw, this check is only executed after we have at least one result.
And we can too refactor it a little to only call getModeAt() after we got an actual result.

@MarcelGerber
Member

@redmunds @peterflynn FYI, I changed it to a whitelist with only CSS/SASS/SCSS/LESS in it.

@redmunds redmunds self-assigned this Jul 23, 2014
@peterflynn peterflynn and 1 other commented on an outdated diff Aug 6, 2014
src/extensions/default/QuickView/main.js
@@ -251,11 +255,24 @@ define(function (require, exports, module) {
return false;
}
+ function checkForLiteral(match) {
@peterflynn
peterflynn Aug 6, 2014 Member

Drive-by comment: "checkForLiteral()" is a name that leaves things vague about what's returned. Maybe something like "isNamedColor()"?

Similarly for "literalCheck" -- how about "disallowNamedColors" or "ignoreNamedColors"?

@redmunds redmunds and 1 other commented on an outdated diff Aug 13, 2014
src/extensions/default/QuickView/main.js
@@ -53,6 +54,8 @@ define(function (require, exports, module) {
POINTER_HEIGHT = 15, // Pointer height, used to shift popover above pointer (plus a little bit of space)
POPOVER_HORZ_MARGIN = 5; // Horizontal margin
+ var styleLanguages = ["css", "text/x-scss", "sass"];
@redmunds
redmunds Aug 13, 2014 Contributor

Need to add LESS. FYI, In general Brackets plans to support scss, but not sass, but I guess it's OK if sass is accepted here.

@redmunds redmunds commented on the diff Aug 13, 2014
src/extensions/default/QuickView/main.js
// Hyphens do not count as a regex word boundary (\b), so check for those here
do {
colorMatch = colorRegEx.exec(line);
- } while (colorMatch && hyphenOnMatchBoundary(colorMatch, line));
+ if (!colorMatch) {
+ break;
+ }
+ if (ignoreNamedColors === undefined) {
+ var mode = TokenUtils.getModeAt(editor._codeMirror, pos).name;
@redmunds
redmunds Aug 13, 2014 Contributor

TokenUtils.getModeAt() is not a cheap method to call, so we need to minimize the number of times it is called. Until we add support for inline css in style attributes, then it's safe to assume that entire line has same mode, so only need to check it once per line. It's simpler to just pass in mode instead of both editor and pos.

@redmunds
redmunds Aug 13, 2014 Contributor

Actually, can calculate ignoreNamedColors for line and just pass that in.

@MarcelGerber
MarcelGerber Aug 24, 2014 Member

@redmunds getModeAt is only called when there is an actual result and it's only called once per line.

@redmunds
redmunds Sep 4, 2014 Contributor

Ok. I was hoping to make the loop & params a little cleaner, but that's more efficient, so I'm good with it.

@redmunds
Contributor

Done with review.

@redmunds
Contributor
redmunds commented Sep 4, 2014

Thanks. Merging.

@redmunds redmunds merged commit 60ce7af into adobe:master Sep 4, 2014

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details
@MarcelGerber MarcelGerber deleted the MarcelGerber:quick-view-literal branch Sep 5, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment