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

fix pageCountWidgets to get elements by correct class name

This commit is contained in:
Gazook89
2021-11-07 16:47:54 -06:00
parent 1fb63f8be3
commit 9141b93a6b

View File

@@ -107,25 +107,22 @@ const Editor = createClass({
addEditorPageNumbers : function(){ addEditorPageNumbers : function(){
if(!this.refs.codeEditor) return; if(!this.refs.codeEditor) return;
if(this.state.view === 'text') { if(this.state.view === 'text') {
let editorPageCount = 2; // start counting from page 2
const codeMirror = this.refs.codeEditor.codeMirror; const codeMirror = this.refs.codeEditor.codeMirror;
const pageCountWidgets = document.getElementsByClassName('editor-page'); const pageCountWidgets = document.getElementsByClassName('editor-page-count');
for (let x=pageCountWidgets.length - 1;x>=0;x--) pageCountWidgets[x].remove();
for(let x=pageCountWidgets.length - 1;x>=0;x--) pageCountWidgets[x].remove(); let editorPageCount = 2; // start counting from page 2
console.log(editorPageCount);
const lineNumbers = _.reduce(this.props.brew.text.split('\n'), (r, line, lineNumber)=>{ const lineNumbers = _.reduce(this.props.brew.text.split('\n'), (r, line, lineNumber)=>{
if(this.props.renderer == 'legacy') { if(this.props.renderer == 'legacy') {
if(line.includes('\\page')) { if(line.includes('\\page')) {
const testElement = Object.assign(document.createElement('div'), { const testElement = Object.assign(document.createElement('div'), {
className : 'editor-page-count', className : 'editor-page-count',
textContent : editorPageCount textContent : editorPageCount
}); });
codeMirror.addWidget({ line: lineNumber, ch: 0}, testElement); codeMirror.addWidget({ line: lineNumber, ch: 0 }, testElement);
testElement.style.top = parseInt(testElement.style.top) - 12.5 + 'px'; testElement.style.top = `${parseInt(testElement.style.top) - 12.5}px`;
testElement.style.left = 'unset'; testElement.style.left = 'unset';
editorPageCount = editorPageCount + 1; editorPageCount = editorPageCount + 1;
r.push(lineNumber); r.push(lineNumber);
@@ -135,11 +132,11 @@ const Editor = createClass({
if(this.props.renderer == 'V3') { if(this.props.renderer == 'V3') {
if(line.match(/^\\page$/)){ if(line.match(/^\\page$/)){
const testElement = Object.assign(document.createElement('div'), { const testElement = Object.assign(document.createElement('div'), {
className : 'editor-page-count', className : 'editor-page-count',
textContent : editorPageCount textContent : editorPageCount
}); });
codeMirror.addWidget({ line: lineNumber, ch: 0}, testElement); codeMirror.addWidget({ line: lineNumber, ch: 0 }, testElement);
testElement.style.top = parseInt(testElement.style.top) - 12.5 + 'px'; testElement.style.top = `${parseInt(testElement.style.top) - 12.5}px`;
testElement.style.left = 'unset'; testElement.style.left = 'unset';
editorPageCount = editorPageCount + 1; editorPageCount = editorPageCount + 1;
r.push(lineNumber); r.push(lineNumber);