0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 18:32:41 +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,39 +107,36 @@ const Editor = createClass({
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();
const pageCountWidgets = document.getElementsByClassName('editor-page-count');
for (let x=pageCountWidgets.length - 1;x>=0;x--) pageCountWidgets[x].remove();
console.log(editorPageCount);
let editorPageCount = 2; // start counting from page 2
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',
className : 'editor-page-count',
textContent : editorPageCount
});
codeMirror.addWidget({ line: lineNumber, ch: 0}, testElement);
testElement.style.top = parseInt(testElement.style.top) - 12.5 + 'px';
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',
className : 'editor-page-count',
textContent : editorPageCount
});
codeMirror.addWidget({ line: lineNumber, ch: 0}, testElement);
testElement.style.top = parseInt(testElement.style.top) - 12.5 + 'px';
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);