Fix AssertionError in bring_to_front

This commit is contained in:
Isaiah Odhner 2023-05-04 18:38:32 -04:00
parent 42ca86f7eb
commit 076b4bd681

View File

@ -140,7 +140,12 @@ class Window(Container):
def bring_to_front(self) -> None:
"""Reorder the window to be last so it renders on top."""
assert isinstance(self.parent, Widget)
if not self.parent:
# Can happen when saying Yes to "Save changes to X?" prompt during Save As
# I got this using automation (so it might need to be fast to happen):
# textual run --dev "src/textual_paint/paint.py --language en --clear-screen --inspect-layout --restart-on-changes question_icon.ans" --press ctrl+shift+s,.,_,r,i,c,h,_,c,o,n,s,o,l,e,_,m,a,r,k,u,p,enter,enter
return
assert isinstance(self.parent, Widget), "Window parent should be a Widget, but got: " + repr(self.parent)
if self.parent.children[-1] is not self:
self.parent.move_child(self, after=self.parent.children[-1])