From 9a7e2e732388b21479d0d1559119f60d7ce69371 Mon Sep 17 00:00:00 2001 From: Eugene Date: Thu, 2 Apr 2026 19:15:14 +0300 Subject: [PATCH] fix: correct scroll offset when clearing search in tree view --- ui/tab_treeview.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ui/tab_treeview.go b/ui/tab_treeview.go index a67656e..4e1883a 100644 --- a/ui/tab_treeview.go +++ b/ui/tab_treeview.go @@ -191,12 +191,20 @@ func renderTreeView(gtx C, app *appstate.State, theme *material.Theme) D { if targetIndex < len(app.Tree.Nodes) { app.Tree.SelectedNode = targetIndex app.Tree.SelectedNodePath = "" + + // Directly position list to show the selected item. + // Height caches are empty after tree rebuild, so + // calculateSmartScrollPositionVariable would use inaccurate + // fallback heights. Place the item a few rows from the top. + first := max(targetIndex-treeRestoreContextRows, 0) + app.Tree.List.Position.First = first + app.Tree.List.Position.Offset = 0 } selectedTreeNode = app.Tree.SelectedNode app.StoreMu.Unlock() - needScrollToSel = true // Update local var so scroll runs in the SAME frame + needScrollToSel = true app.NeedScrollToSel = true app.Tree.NeedInitialSel = false