From 9f7ee39b0961143e443ef126a4ad0d1685ae2155 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Wed, 11 May 2022 10:46:49 +1200 Subject: [PATCH] Use BoundingRect.bottom to determine page --- client/homebrew/editor/editor.jsx | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/client/homebrew/editor/editor.jsx b/client/homebrew/editor/editor.jsx index d557d40b4..d15714bae 100644 --- a/client/homebrew/editor/editor.jsx +++ b/client/homebrew/editor/editor.jsx @@ -189,18 +189,20 @@ const Editor = createClass({ sourceJump : function(targetLine=null){ if(this.isText() || (this.isStyle() && targetLine == 0)) { if(targetLine == null) { - const brewPosition = window.frames['BrewRenderer'].contentDocument.getElementsByClassName('brewRenderer').item(0).scrollTop; - const pageCollection = window.frames['BrewRenderer'].contentDocument.getElementsByClassName('page'); - - let currentPage = 0; - let currentPagePosition = 0; - while (currentPagePosition < brewPosition && currentPage < pageCollection.length) { - currentPagePosition = currentPagePosition + pageCollection[currentPage].getBoundingClientRect().bottom; - currentPage++; - }; - targetLine = 0; + const pageCollection = window.frames['BrewRenderer'].contentDocument.getElementsByClassName('page'); + const brewRendererHeight = window.frames['BrewRenderer'].contentDocument.getElementsByClassName('brewRenderer').item(0).getBoundingClientRect().height; + + let currentPage = 1; + for (const page of pageCollection) { + if(page.getBoundingClientRect().bottom > (brewRendererHeight / 2)) { + const pageId = page.id; + currentPage = parseInt(pageId.slice(1, pageId.length)) || 1; + break; + } + } + if(currentPage > 1){ const textString = this.props.brew.text.split('\\page').slice(0, currentPage-1).join('\\page'); const textPosition = textString.length;