From 7df031715fabd6eb84ef315e8fe78dc7d0b7344d Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Mon, 1 Dec 2025 04:21:20 -0500 Subject: Fix Agent Log scroll position reset on HTMX poll MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Perfect! Let me create a summary of what was implemented: I successfully implemented **Option A** (save/restore scroll position) f **File: `Omni/Jr/Web.hs`** (lines 2418-2419) Added two HTMX event handlers to the `pollAttrs` in the `renderAgentLogS 1. **`hx-on::before-request`**: Saves the current scroll position of the ```javascript var log = this.querySelector('.agent-log'); if(log) this.dataset.scro ``` 2. **`hx-on::after-swap`**: Restores the saved scroll position after the ```javascript var log = this.querySelector('.agent-log'); if(log && this.dataset.sc ``` - Before each HTMX poll request (every 3 seconds), the current scroll po - After the content is swapped (innerHTML replacement), the scroll posit - This preserves the user's reading position even though the DOM is comp - The existing auto-scroll behavior for the "near bottom" case is preser - ✅ `bild --test Omni/Jr.hs` - All tests pass (12/12) - ✅ `lint Omni/Jr/Web.hs` - No ormolu or hlint issues The fix is minimal, non-invasive, and uses HTMX's built-in event system Task-Id: t-197.7 --- Omni/Jr/Web.hs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'Omni/Jr/Web.hs') diff --git a/Omni/Jr/Web.hs b/Omni/Jr/Web.hs index d528365..88e0442 100644 --- a/Omni/Jr/Web.hs +++ b/Omni/Jr/Web.hs @@ -2414,7 +2414,9 @@ renderAgentLogSection tid events status now = do then [ Lucid.makeAttribute "hx-get" ("/partials/task/" <> tid <> "/events"), Lucid.makeAttribute "hx-trigger" "every 3s", - Lucid.makeAttribute "hx-swap" "innerHTML" + Lucid.makeAttribute "hx-swap" "innerHTML", + Lucid.makeAttribute "hx-on::before-request" "var log = this.querySelector('.agent-log'); if(log) this.dataset.scroll = log.scrollTop", + Lucid.makeAttribute "hx-on::after-swap" "var log = this.querySelector('.agent-log'); if(log && this.dataset.scroll) log.scrollTop = this.dataset.scroll" ] else [] Lucid.div_ ([Lucid.class_ "agent-log-section", Lucid.id_ "agent-log-container"] <> pollAttrs) <| do -- cgit v1.2.3