Skip to content

Commit

Permalink
handle unchanged index without always_update
Browse files Browse the repository at this point in the history
  • Loading branch information
TomJGooding committed Oct 28, 2024
1 parent 336a954 commit d330ecd
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/textual/widgets/_list_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,16 @@ def pop(self, index: Optional[int] = None) -> AwaitComplete:
async def do_pop():
await item_to_remove.remove()
if self.index is not None:
if normalized_index == self.index:
if normalized_index < self.index:
self.index -= 1
elif normalized_index == self.index:
old_index = self.index
# Force a re-validation of the index
self.index = self.index
elif normalized_index < self.index:
self.index = self.index - 1
# If the index hasn't changed, the watcher won't be called
# but we need to update the highlighted item
if old_index == self.index:
self.watch_index(old_index, self.index)

return AwaitComplete(do_pop())

Expand Down Expand Up @@ -299,7 +305,13 @@ async def do_remove_items():
if removed_before_highlighted:
self.index -= removed_before_highlighted
elif self.index in normalized_indices:
old_index = self.index
# Force a re-validation of the index
self.index = self.index
# If the index hasn't changed, the watcher won't be called
# but we need to update the highlighted item
if old_index == self.index:
self.watch_index(old_index, self.index)

return AwaitComplete(do_remove_items())

Expand Down

0 comments on commit d330ecd

Please sign in to comment.