@@ -230,6 +230,7 @@ define(function (require, exports, module) {
230230 // Add listener for all editor changes
231231 EditorManager . on ( "activeEditorChange" , function ( event , newEditor , oldEditor ) {
232232 if ( newEditor && newEditor . isGutterActive ( GUTTER_NAME ) ) {
233+ console . time ( "xxxxxxxxxxx" ) ;
233234 newEditor . off ( "cursorActivity.colorPreview" ) ;
234235 newEditor . on ( "cursorActivity.colorPreview" , _cursorActivity ) ;
235236 // Unbind the previous editor's change event if it exists
@@ -240,6 +241,7 @@ define(function (require, exports, module) {
240241 newEditor . on ( "change" , onChanged ) ;
241242 showColorMarks ( ) ;
242243 _cursorActivity ( null , newEditor ) ;
244+ console . timeEnd ( "xxxxxxxxxxx" ) ;
243245 }
244246 } ) ;
245247
@@ -317,6 +319,16 @@ define(function (require, exports, module) {
317319 return token . type !== "comment" ;
318320 }
319321
322+ function isAlphanumeric ( char ) {
323+ return / ^ [ a - z 0 - 9 - @ $ ] $ / i. test ( char ) ;
324+ }
325+ function _isColor ( segment , colorInSegment , colorIndex ) {
326+ const previousChar = colorIndex === 0 ? "" : segment . charAt ( colorIndex - 1 ) ;
327+ const endIndex = colorIndex + colorInSegment . length ;
328+ const nextChar = endIndex === segment . length ? "" : segment . charAt ( endIndex ) ;
329+ return ! isAlphanumeric ( previousChar ) && ! isAlphanumeric ( nextChar ) ;
330+ }
331+
320332 /**
321333 * Detects valid colors in a given line of text
322334 *
@@ -329,7 +341,7 @@ define(function (require, exports, module) {
329341 const languageID = editor . document . getLanguage ( ) . getId ( ) ;
330342
331343 // to make sure that code doesn't break when lineText is null.
332- if ( ! lineText ) {
344+ if ( ! lineText || lineText . length > 1000 ) { // too long lines we cant scan, maybe minified?
333345 return [ ] ;
334346 }
335347
@@ -345,6 +357,10 @@ define(function (require, exports, module) {
345357
346358 colorMatches . forEach ( colorMatch => {
347359 const colorIndex = lineMatch . index + colorMatch . index ;
360+ // this will also allow color name like vars eg: --red-main or @heading-green. we need to omit those
361+ if ( ! _isColor ( lineMatch [ 0 ] , colorMatch [ 0 ] , colorMatch . index ) ) {
362+ return ;
363+ }
348364
349365 // Check if the color is within a comment
350366 const token = editor . getToken ( { line : lineNumber , ch : colorIndex } , true ) ;
0 commit comments