From e5ab2235717e6eba283a8c6765c8366e4e8dfa34 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Tue, 10 Sep 2024 01:25:26 -0400 Subject: [PATCH] Better line position (viewport has some margin) --- client/homebrew/editor/editor.jsx | 2 +- shared/naturalcrit/codeEditor/codeEditor.jsx | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/client/homebrew/editor/editor.jsx b/client/homebrew/editor/editor.jsx index 09af827fc..e2b28cdc1 100644 --- a/client/homebrew/editor/editor.jsx +++ b/client/homebrew/editor/editor.jsx @@ -189,7 +189,7 @@ const Editor = createClass({ if (atCursor) lines = lines.slice(0, this.codeEditor.current.getCursorPosition().line + 1); // get cursor page else - lines = lines.slice(0, this.codeEditor.current.getViewport().from + 1); // get view page + lines = lines.slice(0, this.codeEditor.current.getTopVisibleLine() + 1); // get view page return _.reduce(lines, (r, line)=>{ if( diff --git a/shared/naturalcrit/codeEditor/codeEditor.jsx b/shared/naturalcrit/codeEditor/codeEditor.jsx index 64dab05d0..ac930177a 100644 --- a/shared/naturalcrit/codeEditor/codeEditor.jsx +++ b/shared/naturalcrit/codeEditor/codeEditor.jsx @@ -399,8 +399,10 @@ const CodeEditor = createClass({ getCursorPosition : function(){ return this.codeMirror.getCursor(); }, - getViewport : function(){ - return this.codeMirror.getViewport(); + getTopVisibleLine : function(){ + const rect = this.codeMirror.getWrapperElement().getBoundingClientRect(); + const topVisibleLine = this.codeMirror.lineAtHeight(rect.top, "window"); + return topVisibleLine; }, updateSize : function(){ this.codeMirror.refresh();