From 388bd7cefa079ea07195c7668f07f357ceee0739 Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Fri, 5 Oct 2012 15:41:58 +0100 Subject: [PATCH] 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 --- lib/coder.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/coder.js b/lib/coder.js index 55bb3f9..864c4ce 100644 --- a/lib/coder.js +++ b/lib/coder.js @@ -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);