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

initial commit to add programmatic page counts in editor

update element classname to be more descriptive, remove some commented code.
This commit is contained in:
Gazook89
2021-11-06 22:28:12 -05:00
parent 954fb6064e
commit 1fb63f8be3
2 changed files with 54 additions and 8 deletions

View File

@@ -52,6 +52,7 @@ const Editor = createClass({
componentDidMount : function() { componentDidMount : function() {
this.updateEditorSize(); this.updateEditorSize();
this.addEditorPageNumbers();
this.highlightCustomMarkdown(); this.highlightCustomMarkdown();
window.addEventListener('resize', this.updateEditorSize); window.addEventListener('resize', this.updateEditorSize);
}, },
@@ -61,6 +62,7 @@ const Editor = createClass({
}, },
componentDidUpdate : function() { componentDidUpdate : function() {
this.addEditorPageNumbers();
this.highlightCustomMarkdown(); this.highlightCustomMarkdown();
}, },
@@ -102,6 +104,53 @@ const Editor = createClass({
}, 1); }, 1);
}, },
addEditorPageNumbers : function(){
if(!this.refs.codeEditor) return;
if(this.state.view === 'text') {
let editorPageCount = 2; // start counting from page 2
const codeMirror = this.refs.codeEditor.codeMirror;
const pageCountWidgets = document.getElementsByClassName('editor-page');
for(let x=pageCountWidgets.length - 1;x>=0;x--) pageCountWidgets[x].remove();
console.log(editorPageCount);
const lineNumbers = _.reduce(this.props.brew.text.split('\n'), (r, line, lineNumber)=>{
if(this.props.renderer == 'legacy') {
if(line.includes('\\page')) {
const testElement = Object.assign(document.createElement('div'), {
className : 'editor-page-count',
textContent : editorPageCount
});
codeMirror.addWidget({ line: lineNumber, ch: 0}, testElement);
testElement.style.top = parseInt(testElement.style.top) - 12.5 + 'px';
testElement.style.left = 'unset';
editorPageCount = editorPageCount + 1;
r.push(lineNumber);
}
}
if(this.props.renderer == 'V3') {
if(line.match(/^\\page$/)){
const testElement = Object.assign(document.createElement('div'), {
className : 'editor-page-count',
textContent : editorPageCount
});
codeMirror.addWidget({ line: lineNumber, ch: 0}, testElement);
testElement.style.top = parseInt(testElement.style.top) - 12.5 + 'px';
testElement.style.left = 'unset';
editorPageCount = editorPageCount + 1;
r.push(lineNumber);
}
}
return r;
}, []);
return lineNumbers;
}
},
highlightCustomMarkdown : function(){ highlightCustomMarkdown : function(){
if(!this.refs.codeEditor) return; if(!this.refs.codeEditor) return;
if(this.state.view === 'text') { if(this.state.view === 'text') {
@@ -111,6 +160,7 @@ const Editor = createClass({
const customHighlights = codeMirror.getAllMarks(); const customHighlights = codeMirror.getAllMarks();
for (let i=0;i<customHighlights.length;i++) customHighlights[i].clear(); for (let i=0;i<customHighlights.length;i++) customHighlights[i].clear();
const lineNumbers = _.reduce(this.props.brew.text.split('\n'), (r, line, lineNumber)=>{ const lineNumbers = _.reduce(this.props.brew.text.split('\n'), (r, line, lineNumber)=>{
//reset custom line styles //reset custom line styles

View File

@@ -5,17 +5,13 @@
.codeEditor{ .codeEditor{
height : 100%; height : 100%;
counter-reset : page;
counter-increment : page;
.pageLine{ .pageLine{
background : #33333328; background : #33333328;
border-top : #339 solid 1px; border-top : #339 solid 1px;
&:after{ }
content : counter(page); .editor-page-count{
counter-increment : page; color : grey;
float : right; right : 12px;
color : gray;
}
} }
.columnSplit{ .columnSplit{
font-style : italic; font-style : italic;