0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-26 05:12:39 +00:00

remove "in viewport" requirement for markdown highlight/pg numbers

This commit is contained in:
Gazook89
2021-12-03 20:20:40 -06:00
parent 372d33271d
commit 5cd45a1413
2 changed files with 11 additions and 21 deletions

View File

@@ -115,11 +115,6 @@ const Editor = createClass({
let editorPageCount = 2; // start page count from page 2
// get top and bottom line numbers currently in editor viewport
const viewportRect = codeMirror.getWrapperElement().getBoundingClientRect();
const topVisibleLine = codeMirror.lineAtHeight(viewportRect.top, 'window') - 50;
const bottomVisibleLine = codeMirror.lineAtHeight(viewportRect.bottom, 'window') + 50;
_.forEach(this.props.brew.text.split('\n'), (line, lineNumber)=>{
//reset custom line styles
@@ -129,17 +124,15 @@ const Editor = createClass({
// Legacy Codemirror styling
if(this.props.renderer == 'legacy') {
if(line.includes('\\page')){
// add a check here to see if in current viewport
if(lineNumber > topVisibleLine && lineNumber < bottomVisibleLine){
// 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 = 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;
};
}
@@ -147,8 +140,6 @@ const Editor = createClass({
// New Codemirror styling for V3 renderer
if(this.props.renderer == 'V3') {
if(line.match(/^\\page$/)){
// add a check here to see if in current viewport,
if(lineNumber > topVisibleLine && lineNumber < bottomVisibleLine){
// 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'), {
@@ -156,8 +147,8 @@ const Editor = createClass({
textContent : editorPageCount
});
codeMirror.setBookmark({ line: lineNumber, ch: line.length }, pageCountElement);
}
editorPageCount = editorPageCount + 1;
editorPageCount += 1;
}
if(line.match(/^\\column$/)){

View File

@@ -114,7 +114,6 @@ const CodeEditor = createClass({
// Note: codeMirror passes a copy of itself in this callback. cm === this.codeMirror. Either one works.
this.codeMirror.on('change', (cm)=>{this.props.onChange(cm.getValue());});
this.codeMirror.on('viewportChange', _.debounce((cm)=>{this.props.onChange(cm.getValue());}, 200));
this.updateSize();
},