From 5cd45a1413656855fe9fb07347ecaa68e43e0516 Mon Sep 17 00:00:00 2001 From: Gazook89 <58999374+Gazook89@users.noreply.github.com> Date: Fri, 3 Dec 2021 20:20:40 -0600 Subject: [PATCH] remove "in viewport" requirement for markdown highlight/pg numbers --- client/homebrew/editor/editor.jsx | 31 +++++++------------- shared/naturalcrit/codeEditor/codeEditor.jsx | 1 - 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/client/homebrew/editor/editor.jsx b/client/homebrew/editor/editor.jsx index f2428e906..49649bf1d 100644 --- a/client/homebrew/editor/editor.jsx +++ b/client/homebrew/editor/editor.jsx @@ -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$/)){ diff --git a/shared/naturalcrit/codeEditor/codeEditor.jsx b/shared/naturalcrit/codeEditor/codeEditor.jsx index a23603908..01eca0114 100644 --- a/shared/naturalcrit/codeEditor/codeEditor.jsx +++ b/shared/naturalcrit/codeEditor/codeEditor.jsx @@ -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(); },