Skip to content

Commit

Permalink
ensure pop error is original index rather than normalized
Browse files Browse the repository at this point in the history
  • Loading branch information
TomJGooding committed Oct 17, 2024
1 parent 2abce6d commit 643c2d9
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/textual/widgets/_list_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,16 +247,15 @@ def pop(self, index: Optional[int] = None) -> AwaitComplete:
raise IndexError("pop from empty list")

index = index if index is not None else -1
if index < 0:
index += len(self)
item_to_remove = self.query("ListItem")[index]
normalized_index = index if index >= 0 else index + len(self)

async def do_pop():
await item_to_remove.remove()
if self.index is not None:
if index == self.index:
if normalized_index == self.index:
self.index = self.index
elif index < self.index:
elif normalized_index < self.index:
self.index = self.index - 1

return AwaitComplete(do_pop())
Expand Down

0 comments on commit 643c2d9

Please sign in to comment.