Skip to content

List: Reset selection state when length decreases#5875

Open
redawl wants to merge 1 commit intofyne-io:developfrom
redawl:list_selection_fix
Open

List: Reset selection state when length decreases#5875
redawl wants to merge 1 commit intofyne-io:developfrom
redawl:list_selection_fix

Conversation

@redawl
Copy link
Copy Markdown
Contributor

@redawl redawl commented Aug 2, 2025

Description:

Fixes #5852

Checklist:

  • Tests included.
  • Lint and formatter run with no errors.
  • Tests all pass.
@coveralls
Copy link
Copy Markdown

Coverage Status

coverage: 62.404% (+0.02%) from 62.388%
when pulling 778372b on redawl:list_selection_fix
into 3ee02e8 on fyne-io:develop.

Comment thread widget/list.go
}

if l.list.currentFocus >= length {
l.list.focused = false
Copy link
Copy Markdown
Member

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...

Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Member

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...

Copy link
Copy Markdown
Contributor Author

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()
}
Copy link
Copy Markdown
Member

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...

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

Labels

None yet

3 participants