Skip to content

tui can loose selected/highlighted value #390

Description

@connerohnesorge
@@ -1724,13 +1724,19 @@ func (m *interactiveModel) rebuildTableForWidth() {
                m.rebuildSpecsTable(width)
        }

-       // Restore cursor position (bounded to row count)
+       // Restore cursor position (bounded to row count).
+       // Use GotoTop + MoveDown instead of SetCursor because SetCursor
+       // does not adjust the viewport YOffset, causing the highlighted
+       // row to be scrolled out of the visible area after a table rebuild.
        rowCount := len(m.table.Rows())
        if rowCount > 0 {
-               if currentCursor >= rowCount {
-                       m.table.SetCursor(rowCount - 1)
-               } else {
-                       m.table.SetCursor(currentCursor)
+               target := currentCursor
+               if target >= rowCount {
+                       target = rowCount - 1
+               }
+               m.table.GotoTop()
+               if target > 0 {
+                       m.table.MoveDown(target)
                }
        }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions