[GH-ISSUE #1044] listbox and tree will select wrong node after mouse scroll end #756

Open
opened 2026-03-04 01:07:30 +03:00 by kerem · 3 comments
Owner

Originally created by @wellcomez on GitHub (Oct 25, 2024).
Original GitHub issue: https://github.com/rivo/tview/issues/1044

remove adjust offset on mouse click #1043

  • list.go , i have fixed
    no need to adjust offset after mouse click . because at this point, offset should be right. no need adjust

  • treeview.go

  • it has more complex state management which need you pay more effort to fix it

  • root cause

    1. after mouse-leftdown, state changes to no movement.
    2. because state is not moving, treeview::process will change offsetY to make old selection node to be visible.
    3. As a result, tree and offsetY will change back to old place.
    4. when leftclick event, old value is used to get wrong node.
    5. User will find click to wrong node
Originally created by @wellcomez on GitHub (Oct 25, 2024). Original GitHub issue: https://github.com/rivo/tview/issues/1044 remove adjust offset on mouse click #1043 - list.go , i have fixed no need to adjust offset after mouse click . because at this point, offset should be right. no need adjust - treeview.go - it has more complex state management which need you pay more effort to fix it - root cause 1. after mouse-leftdown, state changes to no movement. 2. because state is not moving, treeview::process will change offsetY to make old selection node to be visible. 3. As a result, tree and offsetY will change back to old place. 4. when leftclick event, old value is used to get wrong node. 5. User will find click to wrong node
Author
Owner

@rivo commented on GitHub (Nov 2, 2024):

I'd like to ask you to provide a brief piece of code that reproduces the issue you're facing, along with a meaningful description, instead of a — and I'm sorry to say that — badly documented pull request and issue that simply tells me "what I should do".

I don't even understand what the problem is.

<!-- gh-comment-id:2453024224 --> @rivo commented on GitHub (Nov 2, 2024): I'd like to ask you to provide a brief piece of code that reproduces the issue you're facing, along with a meaningful description, instead of a — and I'm sorry to say that — badly documented pull request and issue that simply tells me "what I should do". I don't even understand what the problem is.
Author
Owner

@wellcomez commented on GitHub (Nov 3, 2024):

I'd like to ask you to provide a brief piece of code that reproduces the issue you're facing, along with a meaningful description, instead of a — and I'm sorry to say that — badly documented pull request and issue that simply tells me "what I should do".

I don't even understand what the problem is.

  • There are 9 items in view and view height is 3
  • current Item is 0
  1. scroll view with mouse wheel
  2. after scrollend, click on item 8 in listview
  3. Expect result is current item 8 and 8 be highlighted
  4. Current issue, after click, current item changed but to 0
<!-- gh-comment-id:2453469809 --> @wellcomez commented on GitHub (Nov 3, 2024): > I'd like to ask you to provide a brief piece of code that reproduces the issue you're facing, along with a meaningful description, instead of a — and I'm sorry to say that — badly documented pull request and issue that simply tells me "what I should do". > > I don't even understand what the problem is. - There are 9 items in view and view height is 3 - current Item is 0 1. scroll view with mouse wheel 2. after scrollend, click on item 8 in listview 3. Expect result is current item 8 and 8 be highlighted 4. Current issue, after click, current item changed but to 0
Author
Owner

@ademille commented on GitHub (Apr 9, 2025):

I was just about to write up this same bug. Looks like someone beat me to it.
Here's some simple code to see the problem:

// Demo code for the List primitive.
package main

import (
	"fmt"
	"github.com/rivo/tview"
)

func main() {
	app := tview.NewApplication()
	list := tview.NewList()
	for i := 0; i < 100; i++ {
		list.AddItem(fmt.Sprintf("List item %v", i), "Some explanatory text", 'a'+rune(i), nil)
	}
	if err := app.SetRoot(list, true).EnableMouse(true).Run(); err != nil {
		panic(err)
	}
}
  1. Click on "(a) List item 0".

Image

  1. Scroll down until "(a) List item 0" is no longer visible using the mouse:

Image

  1. Click on "List item 20" and notice that the list jumps back to the view of "List item 0", but it's not selected.

Image

  1. Now scroll down using the mouse to "List item 20" again and notice that it has been selected. The view should have stayed on "List item 20" and not jumped back to "List item 0"

Image

<!-- gh-comment-id:2791110632 --> @ademille commented on GitHub (Apr 9, 2025): I was just about to write up this same bug. Looks like someone beat me to it. Here's some simple code to see the problem: ```go // Demo code for the List primitive. package main import ( "fmt" "github.com/rivo/tview" ) func main() { app := tview.NewApplication() list := tview.NewList() for i := 0; i < 100; i++ { list.AddItem(fmt.Sprintf("List item %v", i), "Some explanatory text", 'a'+rune(i), nil) } if err := app.SetRoot(list, true).EnableMouse(true).Run(); err != nil { panic(err) } } ``` 1. Click on "(a) List item 0". ![Image](https://github.com/user-attachments/assets/3ff5b456-58fb-4b79-b851-74b4c2a8cbdd) 2. Scroll down until "(a) List item 0" is no longer visible using the mouse: ![Image](https://github.com/user-attachments/assets/0aa8e8f7-8469-4bf0-88f4-132dbaf883f1) 3. Click on "List item 20" and notice that the list jumps back to the view of "List item 0", but it's not selected. ![Image](https://github.com/user-attachments/assets/d419a3af-265c-48f6-b081-1f9846d941cf) 4. Now scroll down using the mouse to "List item 20" again and notice that it has been selected. The view should have stayed on "List item 20" and not jumped back to "List item 0" ![Image](https://github.com/user-attachments/assets/3a1bacd2-e26c-4c6d-936c-a87020c5cf78)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#756
No description provided.