0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-04 08:12:39 +00:00

Small cleanup. Reduce redundant code.

This commit is contained in:
Trevor Buckner
2021-12-06 15:36:41 -05:00
parent 23deef7a9a
commit 8acd42fcbe
2 changed files with 13 additions and 28 deletions

View File

@@ -105,14 +105,12 @@ const Editor = createClass({
highlightCustomMarkdown : function(){ highlightCustomMarkdown : function(){
if(!this.refs.codeEditor) return; if(!this.refs.codeEditor) return;
if(this.state.view === 'text') { if(this.state.view === 'text') {
console.log('change');
const codeMirror = this.refs.codeEditor.codeMirror; const codeMirror = this.refs.codeEditor.codeMirror;
//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)=>!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
_.forEach(this.props.brew.text.split('\n'), (line, lineNumber)=>{ _.forEach(this.props.brew.text.split('\n'), (line, lineNumber)=>{
@@ -121,36 +119,23 @@ const Editor = createClass({
codeMirror.removeLineClass(lineNumber, 'background'); codeMirror.removeLineClass(lineNumber, 'background');
codeMirror.removeLineClass(lineNumber, 'text'); codeMirror.removeLineClass(lineNumber, 'text');
// Legacy Codemirror styling // Styling for \page breaks
if(this.props.renderer == 'legacy') { if((this.props.renderer == 'legacy' && line.includes('\\page')) ||
if(line.includes('\\page')){ (this.props.renderer == 'V3' && line.match(/^\\page$/))) {
// add back the original class 'background' but also add the new class '.pageline'
codeMirror.addLineClass(lineNumber, 'background', 'pageLine');
const pageCountElement = Object.assign(document.createElement('span'), {
className : 'editor-page-count',
textContent : editorPageCount
});
codeMirror.setBookmark({ line: lineNumber, ch: line.length }, pageCountElement);
editorPageCount += 1; // add back the original class 'background' but also add the new class '.pageline'
}; codeMirror.addLineClass(lineNumber, 'background', 'pageLine');
const pageCountElement = Object.assign(document.createElement('span'), {
className : 'editor-page-count',
textContent : editorPageCount
});
codeMirror.setBookmark({ line: lineNumber, ch: line.length }, pageCountElement);
} editorPageCount += 1;
};
// New Codemirror styling for V3 renderer // New Codemirror styling for V3 renderer
if(this.props.renderer == 'V3') { if(this.props.renderer == 'V3') {
if(line.match(/^\\page$/)){
// add back the original class 'background' but also add the new class '.pageline'
codeMirror.addLineClass(lineNumber, 'background', 'pageLine');
const pageCountElement = Object.assign(document.createElement('span'), {
className : 'editor-page-count',
textContent : editorPageCount
});
codeMirror.setBookmark({ line: lineNumber, ch: line.length }, pageCountElement);
editorPageCount += 1;
}
if(line.match(/^\\column$/)){ if(line.match(/^\\column$/)){
codeMirror.addLineClass(lineNumber, 'text', 'columnSplit'); codeMirror.addLineClass(lineNumber, 'text', 'columnSplit');
} }

View File

@@ -11,7 +11,7 @@
} }
.editor-page-count{ .editor-page-count{
color : grey; color : grey;
float: right; float : right;
} }
.columnSplit{ .columnSplit{
font-style : italic; font-style : italic;