Skip to content

Commit

Permalink
fix: improving the logic of replacing an item in the deep layers of s…
Browse files Browse the repository at this point in the history
…tack
  • Loading branch information
sassanh committed Jul 12, 2024
1 parent 29a0d3d commit 9ab5053
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- feat: add `_visual_snapshot` to visualize the state of stack for debugging purposes
- fix: avoid user selecting a second item while the screen is being transitioned
- fix: improving the logic of replacing an item in the deep layers of stack

## Version 0.11.16

Expand Down
18 changes: 8 additions & 10 deletions ubo_gui/menu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,12 +709,9 @@ def _replace(
item: Menu | PageWidget,
) -> StackItem:
"""Replace the current menu or application."""
try:
item_index = self.stack.index(stack_item)
except ValueError:
if stack_item not in self.stack:
msg = '`stack_item` not found in stack'
raise ValueError(msg) from None
subscriptions = self.top.subscriptions.copy()
if isinstance(item, Menu):
new_item = StackMenuItem(
menu=item,
Expand All @@ -730,12 +727,13 @@ def _replace(
else:
msg = f'Unsupported type: {type(item)}'
raise TypeError(msg)
self.stack[item_index] = new_item
self.top.subscriptions = subscriptions
self._switch_to(
self.current_screen,
transition=self._no_transition,
)
new_item.subscriptions = stack_item.subscriptions
self.stack[self.stack.index(stack_item)] = new_item
if self.top is new_item:
self._switch_to(
self.current_screen,
transition=self._no_transition,
)
return new_item

@overload
Expand Down

0 comments on commit 9ab5053

Please sign in to comment.