From 9a4cc5f63eb7e71074ed5692127ace4bfd795889 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sat, 20 Jul 2024 14:57:09 +1200 Subject: [PATCH] Add @import folding --- shared/naturalcrit/codeEditor/fold-css.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/shared/naturalcrit/codeEditor/fold-css.js b/shared/naturalcrit/codeEditor/fold-css.js index 29501c4c6..ae43675b6 100644 --- a/shared/naturalcrit/codeEditor/fold-css.js +++ b/shared/naturalcrit/codeEditor/fold-css.js @@ -1,13 +1,14 @@ module.exports = { registerHomebreweryHelper : function(CodeMirror) { CodeMirror.registerHelper('fold', 'homebrewerycss', function(cm, start) { + + // BRACE FOLDING const startMatcher = /\{[ \t]*$/; const endMatcher = /\}[ \t]*$/; const prevLine = cm.getLine(start.line); - if((start.line === cm.firstLine()) && (!cm.getLine(start.line).match(startMatcher))) return null; - if(start.line === cm.firstLine() || prevLine.match(startMatcher)) { + if(prevLine.match(startMatcher)) { const lastLineNo = cm.lastLine(); let end = start.line + 1; let braceCount = 1; @@ -26,6 +27,17 @@ module.exports = { }; } + // IMPORT FOLDING + + const importMatcher = /^@import.*?[;]/; + + if(prevLine.match(importMatcher)) { + return { + from : CodeMirror.Pos(start.line, 0), + to : CodeMirror.Pos(start.line, cm.getLine(start.line).length) + }; + } + return null; }); }