From 4079a2ea5e3e23ecb918f9e88e9d35896b44fb47 Mon Sep 17 00:00:00 2001 From: artur_movsisyan Date: Fri, 27 Dec 2024 15:03:25 +0400 Subject: [PATCH] #3054 fix: Screen jumping, when multi user is editing --- word/Editor/Document.js | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/word/Editor/Document.js b/word/Editor/Document.js index 66a93ea0aa..e49d5cb710 100644 --- a/word/Editor/Document.js +++ b/word/Editor/Document.js @@ -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))) { @@ -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)