From 84181e1ec212928b2ffba8d05757b9400cc6f90d Mon Sep 17 00:00:00 2001 From: Yuyao Huang Date: Sat, 9 May 2026 15:37:34 +0800 Subject: [PATCH] fix: use scrollTop instead of viewport center for in-focus detection handleScrollFocus now finds the task closest to scrollTop (offset) instead of closest to the vertical center of the viewport. This ensures that the saved task matches the user's scroll target. --- static/js/tasks.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/static/js/tasks.js b/static/js/tasks.js index cee2a85..7fdb25c 100644 --- a/static/js/tasks.js +++ b/static/js/tasks.js @@ -83,7 +83,6 @@ async function persistSelectedTask(taskId) { if (goal) { goal.selected_task_id = taskId; } - console.log("Saved selected task:", taskId); } catch (error) { console.error("Failed to persist selected task:", error); } @@ -172,16 +171,13 @@ function handleScrollFocus() { const scrollView = document.getElementById("scroll-view"); const taskItems = document.querySelectorAll(".task-item"); - const scrollViewRect = scrollView.getBoundingClientRect(); - const focusCenter = scrollViewRect.top + scrollViewRect.height / 2; + const scrollTop = scrollView.scrollTop; let closestItem = null; let closestDistance = Infinity; taskItems.forEach(item => { - const itemRect = item.getBoundingClientRect(); - const itemCenter = itemRect.top + itemRect.height / 2; - const distance = Math.abs(itemCenter - focusCenter); + const distance = Math.abs(item.offsetTop - scrollTop); item.classList.remove("in-focus"); @@ -205,9 +201,7 @@ function handleScrollFocus() { } function handleScrollSave() { - // Save the task that has in-focus class (determined by handleScrollFocus) const inFocusTask = document.querySelector(".task-item.in-focus"); - console.log("handleScrollSave: inFocusTask=", inFocusTask?.dataset.taskId, "isInitializing=", isInitializing); if (inFocusTask && !isInitializing) { const taskId = parseInt(inFocusTask.dataset.taskId);