From cc9edcc67c018f05ada60d5273a72f9f26c2c4d3 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sat, 17 Aug 2024 23:11:04 +1200 Subject: [PATCH 1/2] Prevent styling of lines inside folded sections --- client/homebrew/editor/editor.jsx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/client/homebrew/editor/editor.jsx b/client/homebrew/editor/editor.jsx index 1ecdcb22b..4a38fc523 100644 --- a/client/homebrew/editor/editor.jsx +++ b/client/homebrew/editor/editor.jsx @@ -119,8 +119,17 @@ const Editor = createClass({ const codeMirror = this.codeEditor.current.codeMirror; codeMirror.operation(()=>{ // Batch CodeMirror styling + const foldLines = []; //reset custom text styles - const customHighlights = codeMirror.getAllMarks().filter((mark)=>!mark.__isFold); //Don't undo code folding + const customHighlights = codeMirror.getAllMarks().filter((mark)=>{ + // Record details of folded sections + if(mark.__isFold) { + const fold = mark.find(); + foldLines.push({from: fold.from?.line, to: fold.to?.line}); + } + return !mark.__isFold; + }); //Don't undo code folding + for (let i=customHighlights.length - 1;i>=0;i--) customHighlights[i].clear(); let editorPageCount = 2; // start page count from page 2 @@ -132,6 +141,14 @@ const Editor = createClass({ codeMirror.removeLineClass(lineNumber, 'text'); codeMirror.removeLineClass(lineNumber, 'wrap', 'sourceMoveFlash'); + // Don't process lines inside folded text + // If the current lineNumber is inside any folded marks, skip line styling + if(_.filter(foldLines, (fold)=>{ + return lineNumber >= fold.from && lineNumber <= fold.to; + }).length > 0) { + return; + }; + // Styling for \page breaks if((this.props.renderer == 'legacy' && line.includes('\\page')) || (this.props.renderer == 'V3' && line.match(/^\\page$/))) { From 5671728c9736be3fd9ed1a596b683ce7615b5a4f Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Mon, 26 Aug 2024 17:23:44 -0400 Subject: [PATCH 2/2] Change filter to some `some` stops once it finds a true case; `filter` has to process the whole list of folds first. --- client/homebrew/editor/editor.jsx | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/client/homebrew/editor/editor.jsx b/client/homebrew/editor/editor.jsx index bfe438f79..faa2f9827 100644 --- a/client/homebrew/editor/editor.jsx +++ b/client/homebrew/editor/editor.jsx @@ -160,11 +160,8 @@ const Editor = createClass({ // Don't process lines inside folded text // If the current lineNumber is inside any folded marks, skip line styling - if(_.filter(foldLines, (fold)=>{ - return lineNumber >= fold.from && lineNumber <= fold.to; - }).length > 0) { + if (foldLines.some(fold => lineNumber >= fold.from && lineNumber <= fold.to)) return; - }; // Styling for \page breaks if((this.props.renderer == 'legacy' && line.includes('\\page')) || @@ -278,7 +275,7 @@ const Editor = createClass({ // Iterate over conflicting marks and clear them var marks = codeMirror.findMarks(startPos, endPos); marks.forEach(function(marker) { - marker.clear(); + if(!marker.__isFold) marker.clear(); }); codeMirror.markText(startPos, endPos, { className: 'emoji' }); }