Improved regex on CSS values

Looks for hex, rgb/hsl-a or colour name values in their correct format
Need match ? match[0] : '' to handle no match scenarios
This commit is contained in:
Matt Pass
2012-10-05 15:41:58 +01:00
parent 8234b3b063
commit 388bd7cefa

View File

@@ -1308,8 +1308,7 @@ var ICEcoder = {
cM = ICEcoder.getcMInstance();
string = cM.getLine(cM.getCursor().line);
rx = /[a-z0-9#(),.]+/gi;
rx = /(#[\da-f]{3,6}\b|(?:rgb|hsl)a?\([^)]*\)|[a-z]+\b)/gi;
while((match = rx.exec(string)) && cM.getCursor().ch > match.index + match[0].length);
@@ -1321,7 +1320,7 @@ var ICEcoder = {
newBlock.style.position = "absolute";
newBlock.style.display = "block";
newBlock.style.width = newBlock.style.height = "20px";
newBlock.style.background = match;
newBlock.style.background = match ? match[0] : '';
if (newBlock.style.backgroundColor=="") {newBlock.style.display = "none"};
top.document.getElementById('header').appendChild(newBlock);
cM.addWidget(cM.getCursor(), top.document.getElementById('cssColor'), true);