From bb81d6270ff0f7d1c30be95589fd8f9a3f8c2078 Mon Sep 17 00:00:00 2001 From: Huang Xin Date: Thu, 28 May 2026 23:07:49 +0800 Subject: [PATCH] fix(reader): keep Android paginated text selection from jumping back to first rendered section (#4342) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Android-only workaround that pinned the container scroll while text was selected saved `renderer.start` (section-relative) and restored it as `renderer.containerPosition` (absolute). On later sections those two diverge — restoring the small `start` value as `containerPosition` snapped the multi-view scroll back to the first rendered section whenever the OS selection handle drag triggered a scroll. Save and restore the same `containerPosition` value instead. Co-authored-by: Claude Opus 4.7 (1M context) --- .../src/app/reader/hooks/useTextSelector.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/readest-app/src/app/reader/hooks/useTextSelector.ts b/apps/readest-app/src/app/reader/hooks/useTextSelector.ts index d80d6506..9c8b84f3 100644 --- a/apps/readest-app/src/app/reader/hooks/useTextSelector.ts +++ b/apps/readest-app/src/app/reader/hooks/useTextSelector.ts @@ -189,8 +189,12 @@ export const useTextSelector = ( const sel = doc.getSelection() as Selection; if (isValidSelection(sel)) { - if (!selectionPosition.current) { - selectionPosition.current = view?.renderer?.start || null; + if (selectionPosition.current === null) { + // Save the absolute container scroll, not `renderer.start` — the + // latter is section-relative, so restoring it as `containerPosition` + // snaps multi-section paginated views back to the first rendered + // section (#873-related Android regression). + selectionPosition.current = view?.renderer?.containerPosition ?? null; } makeSelection(sel, index, false); } else { @@ -206,8 +210,7 @@ export const useTextSelector = ( const viewSettings = getViewSettings(bookKey); if (viewSettings?.scrolled) return; - if (isTextSelected.current && view?.renderer?.containerPosition && selectionPosition.current) { - console.warn('Keep container position', selectionPosition.current); + if (isTextSelected.current && view?.renderer && selectionPosition.current !== null) { view.renderer.containerPosition = selectionPosition.current; } };