Skip to content

Commit

Permalink
Commit amovsisyan's patch to fix screen jumping
Browse files Browse the repository at this point in the history
Third party patch committed by me (Matthew T) from amovsisyan's patch here:
ONLYOFFICE#4848
  • Loading branch information
amovsisyan authored and Matthew Toseland committed Jan 27, 2025
1 parent be4624f commit e0aaeb6
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion word/Editor/Document.js
Original file line number Diff line number Diff line change
Expand Up @@ -15794,7 +15794,7 @@ CDocument.prototype.private_StoreViewPositions = function(state)
// TODO: Решить проблему, когда видно больше 2 страниц и курсор находится на средней странице
// Использовать положение курсора оказалось не всегда удачно, т.к. при многократном быстром расчете курсор может
// может попасть в поле экрана и тогда скролл потянется сразу за ним, что может быть неверным
if (false && -1 !== cursorPage
if (-1 !== cursorPage
&& ((viewPort[0].Page === cursorPage && cursorY + cursorH > viewPort[0].Y)
|| (viewPort[1].Page === cursorPage && cursorY < viewPort[1].Y)))
{
Expand Down Expand Up @@ -15882,6 +15882,43 @@ CDocument.prototype.private_StoreViewPositions = function(state)
state.AnchorPos = anchorPos;
state.AnchorAlignTop = true;
state.AnchorDistance = xyInfo.Y - viewPort[0].Y;

let currentAnchorPage = state.AnchorPos ? this.private_GetXYByDocumentPosition(state.AnchorPos).Page : -1;
let topViewPage = viewPort[0].Page;

if (currentAnchorPage !== topViewPage)
{
// Calculate the desired Y position relative to viewPort[0].Page
let desiredY = state.AnchorDistance; // The distance from the top of the viewport
let pageHeight = this.Pages[topViewPage] ? this.Pages[topViewPage].Height : 297; // Default A4 height

// Clamp desiredY within the page's height
desiredY = Math.max(0, Math.min(desiredY, pageHeight));

// Find a new anchorPos on viewPort[0].Page at desiredY
let newAnchorPos = this.GetDocumentPositionByXY(topViewPage, 0, desiredY);
if (newAnchorPos)
{
state.AnchorPos = newAnchorPos;
let newXyInfo = this.private_GetXYByDocumentPosition(newAnchorPos);

// Update AnchorDistance with the new Y position
state.AnchorDistance = newXyInfo.Y - viewPort[0].Y;
}
else
{
// Fallback: Set anchorPos to the very top of viewPort[0].Page
newAnchorPos = this.GetDocumentPositionByXY(topViewPage, 0, 0);
if (newAnchorPos)
{
state.AnchorPos = newAnchorPos;
let fallbackXyInfo = this.private_GetXYByDocumentPosition(newAnchorPos);

// Update AnchorDistance with the new Y position
state.AnchorDistance = fallbackXyInfo.Y - viewPort[0].Y;
}
}
}
}
};
CDocument.prototype.Load_DocumentStateAfterLoadChanges = function(State, updateSelection)
Expand Down

0 comments on commit e0aaeb6

Please sign in to comment.