Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#3054 fix: Screen jumping, when multi user is editing #4848

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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