From 451f06ca7408deccaebeeb4decfbe5888b8806a9 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Tue, 3 May 2022 17:24:37 +1200 Subject: [PATCH] Fix `getCurrentPage` --- client/homebrew/editor/editor.jsx | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/client/homebrew/editor/editor.jsx b/client/homebrew/editor/editor.jsx index 04251bd91..c8d3339f4 100644 --- a/client/homebrew/editor/editor.jsx +++ b/client/homebrew/editor/editor.jsx @@ -96,7 +96,7 @@ const Editor = createClass({ }, getCurrentPage : function(){ - const lines = this.props.brew.text.split('\n').slice(0, this.cursorPosition.line + 1); + const lines = this.props.brew.text.split('\n').slice(0, this.refs.codeEditor.getCursorPosition().line + 1); return _.reduce(lines, (r, line)=>{ if(line.indexOf('\\page') !== -1) r++; return r; @@ -174,16 +174,17 @@ const Editor = createClass({ } }, - brewJump : function(page=this.getCurrentPage()){ - if(!document) return; - window.frames['BrewRenderer'].contentDocument.getElementById(`p${page}`).scrollIntoView({ behaviour: 'auto', block: 'start' }); + brewJump : function(targetPage=this.getCurrentPage()){ + if(!window || this.isMeta()) return; + window.frames['BrewRenderer'].contentDocument.getElementById(`p${targetPage}`).scrollIntoView({ behaviour: 'auto', block: 'start' }); // const hashPage = (page != 1) ? `p${page}` : ''; // window.location.hash = hashPage; }, - sourceJump : function(line=1){ - if(!this.isText || !this.isStyle) return; - this.refs.codeEditor.setCursorPosition(line, 1); + sourceJump : function(targetLine=1){ + if(this.isText() || this.isStyle()) { + this.refs.codeEditor.setCursorPosition(targetLine, 0); + } }, //Called when there are changes to the editor's dimensions