-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Limit QuickView to literal color names in some languages #8156
Changes from 4 commits
8efafdf
ad80150
d4a5cb3
72584d6
93e1eaa
64a418c
bf24ee7
8c7fcda
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,8 @@ define(function (require, exports, module) { | |
Menus = brackets.getModule("command/Menus"), | ||
PreferencesManager = brackets.getModule("preferences/PreferencesManager"), | ||
Strings = brackets.getModule("strings"), | ||
ViewUtils = brackets.getModule("utils/ViewUtils"); | ||
ViewUtils = brackets.getModule("utils/ViewUtils"), | ||
TokenUtils = brackets.getModule("utils/TokenUtils"); | ||
|
||
var previewContainerHTML = require("text!QuickViewTemplate.html"); | ||
|
||
|
@@ -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"]; | ||
|
||
prefs = PreferencesManager.getExtensionPrefs("quickview"); | ||
prefs.definePreference("enabled", "boolean", true); | ||
|
||
|
@@ -232,8 +235,9 @@ define(function (require, exports, module) { | |
}; | ||
} | ||
|
||
function execColorMatch(line) { | ||
var colorMatch; | ||
function execColorMatch(editor, line, pos) { | ||
var colorMatch, | ||
literalCheck; | ||
|
||
function hyphenOnMatchBoundary(match, line) { | ||
var beforeIndex, afterIndex; | ||
|
@@ -251,11 +255,24 @@ define(function (require, exports, module) { | |
|
||
return false; | ||
} | ||
function checkForLiteral(match) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
if (match && match[0] && /^[a-z]+$/i.test(match[0])) { // only for color names, not for hex-/rgb-values | ||
return true; | ||
} | ||
} | ||
|
||
// 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 (literalCheck === undefined) { | ||
var mode = TokenUtils.getModeAt(editor._codeMirror, pos).name; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, can calculate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @redmunds There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. I was hoping to make the loop & params a little cleaner, but that's more efficient, so I'm good with it. |
||
literalCheck = styleLanguages.indexOf(mode) === -1; | ||
} | ||
} while (hyphenOnMatchBoundary(colorMatch, line) || | ||
(literalCheck && checkForLiteral(colorMatch))); | ||
|
||
return colorMatch; | ||
} | ||
|
@@ -347,7 +364,7 @@ define(function (require, exports, module) { | |
} | ||
|
||
var gradientMatch = execGradientMatch(line), | ||
match = gradientMatch.match || execColorMatch(line), | ||
match = gradientMatch.match || execColorMatch(editor, line, pos), | ||
cm = editor._codeMirror; | ||
|
||
while (match) { | ||
|
@@ -393,7 +410,7 @@ define(function (require, exports, module) { | |
if (gradientMatch.match) { | ||
gradientMatch = execGradientMatch(line); | ||
} | ||
match = gradientMatch.match || execColorMatch(line); | ||
match = gradientMatch.match || execColorMatch(editor, line, pos); | ||
} | ||
|
||
return null; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* Sample JS for testing the QuickView extension. */ | ||
|
||
function green() { // generate green colors | ||
var color = "green", | ||
tan = Math.tan; | ||
return tan(array["red"], array[red]); | ||
} | ||
darkgray | ||
// #123456 | ||
// :rgb(65, 43, 21) |
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.
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.
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.
Done.