From 2fc7aa454f95dc953c384fdebc4c4a2f90db6005 Mon Sep 17 00:00:00 2001 From: David Bolack Date: Sun, 21 Jul 2024 12:40:49 -0500 Subject: [PATCH] Add data: URL folding for CSS. Regex might need tweaking to catch all cases, but it catches the basics. --- shared/naturalcrit/codeEditor/codeEditor.jsx | 10 +++++++++- shared/naturalcrit/codeEditor/fold-css.js | 12 ++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/shared/naturalcrit/codeEditor/codeEditor.jsx b/shared/naturalcrit/codeEditor/codeEditor.jsx index af9c5c733..cc74a6f0a 100644 --- a/shared/naturalcrit/codeEditor/codeEditor.jsx +++ b/shared/naturalcrit/codeEditor/codeEditor.jsx @@ -433,9 +433,17 @@ const CodeEditor = createClass({ } text = foldPreviewText || `Lines ${from.line+1}-${to.line+1}`; + text = text.replace('{', '').trim(); + + // Extra data url chomping + console.log(text); + text = text.indexOf('data:') > -1 ? `${text.slice(0, text.indexOf('data:') + 5)} ...` : text; + console.log(text); + if(text.length > maxLength) - text = `${text.substr(0, maxLength)}...`; + text = `${text.slice(0, maxLength)}...`; + return `\u21A4 ${text} \u21A6`; } diff --git a/shared/naturalcrit/codeEditor/fold-css.js b/shared/naturalcrit/codeEditor/fold-css.js index b7a2a6da1..f21eaef45 100644 --- a/shared/naturalcrit/codeEditor/fold-css.js +++ b/shared/naturalcrit/codeEditor/fold-css.js @@ -38,6 +38,18 @@ module.exports = { }; } + // data-url folding FOR CSS. + + const dataURLMatcher = /url\(.*?data\:.*\)/; + + if(activeLine.match(dataURLMatcher)) { + return { + from : CodeMirror.Pos(start.line, 0), + to : CodeMirror.Pos(start.line, cm.getLine(start.line).length) + }; + } + + return null; }); }