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

added insert, pop and remove_items methods to ListView #4384

Merged

Conversation

MuongKimhong
Copy link
Contributor

Extend ListView's methods to make it easier to work with ListView.

New methods are:

  1. insert() : insert new items to ListView at specified index
  2. pop() : remove last item from ListView or remove item at specified index
  3. remove_items(): remove multiple items from ListView at specified indices

Returns:
An awaitable object that waits for the direct children to be removed.
"""
if len(self._nodes) == len(indices):
Copy link
Contributor

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.

Copy link
Contributor Author

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.

"""
items_to_remove = []
for index in indices:
items_to_remove.append(self.query("ListItem")[index])
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please have a review

@willmcgugan
Copy link
Collaborator

Thanks

@willmcgugan willmcgugan merged commit 217061c into Textualize:main Apr 19, 2024
18 of 19 checks passed
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 this pull request may close these issues.

3 participants