From 45a9501459433a3b482dd4c03934300d9b0c116e Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Tue, 10 Sep 2024 01:11:28 -0400 Subject: [PATCH] Jump based on scroll position, not cursor position --- client/homebrew/editor/editor.jsx | 13 +++++++++---- shared/naturalcrit/codeEditor/codeEditor.jsx | 3 +++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/client/homebrew/editor/editor.jsx b/client/homebrew/editor/editor.jsx index 3b87c7bcc..09af827fc 100644 --- a/client/homebrew/editor/editor.jsx +++ b/client/homebrew/editor/editor.jsx @@ -158,7 +158,7 @@ const Editor = createClass({ if(!this.props.liveScroll) return; console.log("handleSourceScroll") scrollingJump = true; - this.brewJump(); + this.brewJump(this.getCurrentPage(false)); scrollingJump = false; }, @@ -184,8 +184,13 @@ const Editor = createClass({ }); //TODO: not sure if updateeditorsize needed }, - getCurrentPage : function(){ - const lines = this.props.brew.text.split('\n').slice(0, this.codeEditor.current.getCursorPosition().line + 1); + getCurrentPage : function(atCursor = true){ + let lines = this.props.brew.text.split('\n'); + 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 + return _.reduce(lines, (r, line)=>{ if( (this.props.renderer == 'legacy' && line.indexOf('\\page') !== -1) @@ -357,7 +362,7 @@ const Editor = createClass({ }, brewJump : function(targetPage=this.getCurrentPage()){ - console.log('jumpbrew') + console.log(`jumpBrew to page ${targetPage}`) if(lockBrewJump) return; if(!window) return; lockSourceJump = true; diff --git a/shared/naturalcrit/codeEditor/codeEditor.jsx b/shared/naturalcrit/codeEditor/codeEditor.jsx index 1387edfee..64dab05d0 100644 --- a/shared/naturalcrit/codeEditor/codeEditor.jsx +++ b/shared/naturalcrit/codeEditor/codeEditor.jsx @@ -399,6 +399,9 @@ const CodeEditor = createClass({ getCursorPosition : function(){ return this.codeMirror.getCursor(); }, + getViewport : function(){ + return this.codeMirror.getViewport(); + }, updateSize : function(){ this.codeMirror.refresh(); },