mirror of
https://github.com/rivo/tview.git
synced 2026-04-26 13:25:51 +03:00
[PR #1103] Improving Grid's focus handling and primitive nil checks #1126
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#1126
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/rivo/tview/pull/1103
Author: @zveinn
Created: 7/8/2025
Status: 🔄 Open
Base:
master← Head:clearing-grid-focus📝 Commits (2)
7257a43Clearing grid focus when a new focused item is addedc35c049adding nil check for p📊 Changes
1 file changed (+10 additions, -0 deletions)
View changed files
📝
grid.go(+10 -0)📄 Description
Hey, love the library. I was playing around with the Grid view and noticed that the Grid.AddItem wouldn't respect the focus boolean sometimes. Then I checked the Draw method for the Grid and noticed that only the one element is picked for focus during a draw and it's not necessarily the latest one added.
A small sidequest: When a nil primitive is added to the Grid, it will panic when trying to deal with inputHandling. So I just added a check for p == nil to prevent nil primitives from being added to the table. This way, whomever is using this library can just insert things into the Grid without having to nil check all over the place.
You can test this by making a split pane grid and then adding two tables into each pane. It'll work the first time you call AddItem on any Primitive, but subsiquent AddItems call will mess up the focus. (maybe i'm using it wrong ?)
my test repo: https://github.com/zveinn/term-test
So I wrote a small loop to clear focus on all elements to force focus on the added item (only if focus is true)
I'm not sure if it's intended to have multiple elements within a grid that can have focus at the same time, if so then feel free to close the PR.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.