-
Notifications
You must be signed in to change notification settings - Fork 815
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
added insert, pop and remove_items methods to ListView #4384
added insert, pop and remove_items methods to ListView #4384
Conversation
src/textual/widgets/_list_view.py
Outdated
Returns: | ||
An awaitable object that waits for the direct children to be removed. | ||
""" | ||
if len(self._nodes) == len(indices): |
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.
If there are two items in the ListView
and the developer passed [0, 0]
as the indices
this will have unintended consequences.
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.
Thank for pointing it out! I have removed that block as it's not necessary.
src/textual/widgets/_list_view.py
Outdated
""" | ||
items_to_remove = [] | ||
for index in indices: | ||
items_to_remove.append(self.query("ListItem")[index]) |
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.
You could cache that query. Otherwise it would be performed once per loop.
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.
please have a review
Thanks |
Extend ListView's methods to make it easier to work with ListView.
New methods are:
insert()
: insert new items to ListView at specified indexpop()
: remove last item from ListView or remove item at specified indexremove_items()
: remove multiple items from ListView at specified indices