-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
List: Reset selection state when length decreases #5875
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
@@ -703,6 +703,21 @@ func (l *listLayout) updateList(newOnly bool) { | |||
fyne.LogError("Missing UpdateCell callback required for List", nil) | |||
} | |||
|
|||
if l.list.currentFocus >= length { | |||
l.list.focused = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it should look like it lost focus - the actual focus won't have changed...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this check, even though we removed the selection when the list shrunk, when the list grows again the previously selected row shows as focused, which is incorrect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree what you describe is not correct - but I'm not sure your solution is either.
If you're editing an Entry and SetText is called to shorter the cursor would move to accommodate but it would not unfocus the entry...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you saying if there is an entry inside the list row? at least with this code, the entry is properly unfocused as well:
package main
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
)
func main() {
a := app.New()
w := a.NewWindow("Scroll Test")
w.Resize(fyne.NewSize(800, 800))
items := []string{
"Item1",
"Item2",
"Item3",
}
populateList := true
button := widget.NewButton("Click to toggle list", func() {})
list := widget.NewList(
func() int {
if populateList {
return len(items)
}
return 0
},
func() fyne.CanvasObject {
return widget.NewEntry()
},
func(lii widget.ListItemID, co fyne.CanvasObject) {
co.(*widget.Entry).OnChanged = func(s string) {
items[lii] = s
}
co.(*widget.Entry).SetText(items[lii])
},
)
button.OnTapped = func() {
populateList = !populateList
list.Refresh()
}
w.SetContent(container.NewBorder(button, nil, nil, nil, list))
w.ShowAndRun()
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you saying if there is an entry inside the list row?
No.
I was using Entry as an illustration of the focus model. Unless the user focuses another widget the list remains focus and so we shouldn't hide the focus state...
Description:
Fixes #5852
Checklist: