mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-08 18:22:40 +00:00
Prevent styling of lines inside folded sections
This commit is contained in:
@@ -119,8 +119,17 @@ const Editor = createClass({
|
|||||||
const codeMirror = this.codeEditor.current.codeMirror;
|
const codeMirror = this.codeEditor.current.codeMirror;
|
||||||
|
|
||||||
codeMirror.operation(()=>{ // Batch CodeMirror styling
|
codeMirror.operation(()=>{ // Batch CodeMirror styling
|
||||||
|
const foldLines = [];
|
||||||
//reset custom text styles
|
//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();
|
for (let i=customHighlights.length - 1;i>=0;i--) customHighlights[i].clear();
|
||||||
|
|
||||||
let editorPageCount = 2; // start page count from page 2
|
let editorPageCount = 2; // start page count from page 2
|
||||||
@@ -132,6 +141,14 @@ const Editor = createClass({
|
|||||||
codeMirror.removeLineClass(lineNumber, 'text');
|
codeMirror.removeLineClass(lineNumber, 'text');
|
||||||
codeMirror.removeLineClass(lineNumber, 'wrap', 'sourceMoveFlash');
|
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
|
// Styling for \page breaks
|
||||||
if((this.props.renderer == 'legacy' && line.includes('\\page')) ||
|
if((this.props.renderer == 'legacy' && line.includes('\\page')) ||
|
||||||
(this.props.renderer == 'V3' && line.match(/^\\page$/))) {
|
(this.props.renderer == 'V3' && line.match(/^\\page$/))) {
|
||||||
|
|||||||
Reference in New Issue
Block a user