List: Reset selection state when length decreases#5875
List: Reset selection state when length decreases#5875redawl wants to merge 1 commit intofyne-io:developfrom
Conversation
| } | ||
|
|
||
| if l.list.currentFocus >= length { | ||
| l.list.focused = false |
There was a problem hiding this comment.
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.
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.
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.
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.
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: