Skip to content

Commit

Permalink
fix(listview): fix remove_items
Browse files Browse the repository at this point in the history
  • Loading branch information
TomJGooding committed Jul 14, 2024
1 parent 66f2e0c commit f7a1f5a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/textual/widgets/_list_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def remove_items(self, indices: Iterable[int]) -> AwaitRemove:
for index in indices:
items_to_remove.append(items[index])

await_remove = items.remove()
await_remove = self.app._prune(*items_to_remove, parent=self)
return await_remove

def action_select_cursor(self) -> None:
Expand Down
32 changes: 32 additions & 0 deletions tests/listview/test_listview_remove_items.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from textual.app import App, ComposeResult
from textual.widgets import ListView, ListItem, Label


class ListViewApp(App[None]):
def compose(self) -> ComposeResult:
yield ListView(
ListItem(Label("0")),
ListItem(Label("1")),
ListItem(Label("2")),
ListItem(Label("3")),
ListItem(Label("4")),
ListItem(Label("5")),
ListItem(Label("6")),
ListItem(Label("7")),
ListItem(Label("8")),
)


async def test_listview_remove_items() -> None:
"""Regression test for https://github.com/Textualize/textual/issues/4735"""
app = ListViewApp()
async with app.run_test() as pilot:
listview = pilot.app.query_one(ListView)
assert len(listview) == 9
await listview.remove_items(range(4, 9))
assert len(listview) == 4


if __name__ == "__main__":
app = ListViewApp()
app.run()

0 comments on commit f7a1f5a

Please sign in to comment.