0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 18:32:41 +00:00

Use BoundingRect.bottom to determine page

This commit is contained in:
G.Ambatte
2022-05-11 10:46:49 +12:00
parent 412ac5f331
commit 9f7ee39b09

View File

@@ -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;