Skip to content
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

Calling remove_items or pop on a ListView does not update index or highlighting #5114

Closed
chriskingio opened this issue Oct 13, 2024 · 3 comments · Fixed by #5135
Closed

Calling remove_items or pop on a ListView does not update index or highlighting #5114

chriskingio opened this issue Oct 13, 2024 · 3 comments · Fixed by #5135

Comments

@chriskingio
Copy link

It seems that calling pop (or remove_items, though that's not what I'm using for my use case) does not correctly update highlighting (presumably because calling pop does not update the index).

A small reproduction is as follows:

from textual.app import App, ComposeResult
from textual.widgets import ListItem, ListView, Footer


class TestApp(App):
    BINDINGS = [
        ('a', 'add', 'Adds a blank item'),
        ('d', 'delete_highlighted', 'Deletes the highlighted cell'),
    ]

    _listview: ListView

    def compose(self) -> ComposeResult:
        self._listview = ListView(ListItem())

        yield Footer()
        yield self._listview

    def action_add(self):
        self._listview.append(ListItem())

    def action_delete_highlighted(self):
        index = self._listview.index
        self._listview.pop(index)


if __name__ == '__main__':
    TestApp().run()

Spawning a few items and trying to delete them does not set any highlighting, only manually updating the index will do that.

Textual Diagnostics

Versions

Name Value
Textual 0.83.0
Rich 13.9.2

Python

Name Value
Version 3.12.1
Implementation CPython
Compiler Clang 17.0.6
Executable /home/king/Projects/private/.venv/bin/python

Operating System

Name Value
System Linux
Release 6.10.11-amd64
Version #1 SMP PREEMPT_DYNAMIC Debian 6.10.11-1 (2024-09-22)

Terminal

Name Value
Terminal Application Unknown
TERM xterm-256color
COLORTERM truecolor
FORCE_COLOR Not set
NO_COLOR Not set

Rich Console options

Name Value
size width=223, height=76
legacy_windows False
min_width 1
max_width 223
is_terminal True
encoding utf-8
max_height 76
justify None
overflow None
no_wrap False
highlight None
markup None
height None
Copy link

We found the following entries in the FAQ which you may find helpful:

Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.

This is an automated reply, generated by FAQtory

@TomJGooding
Copy link
Contributor

TomJGooding commented Oct 15, 2024

Good catch - it looks like the index (and therefore the highlight) isn't properly accounted for when items are removed.

I'm also wondering if these ListView methods should return an AwaitComplete rather than AwaitRemove, to ensure that any re-validation of the index is done only after the items are removed?

Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants