mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
snappier command palette
This commit is contained in:
@@ -926,6 +926,23 @@ class App(Generic[ReturnType], DOMNode):
|
|||||||
if not self._batch_count:
|
if not self._batch_count:
|
||||||
self.check_idle()
|
self.check_idle()
|
||||||
|
|
||||||
|
def _delay_update(self, delay: float = 0.05) -> None:
|
||||||
|
"""Delay updates for a short period of time.
|
||||||
|
|
||||||
|
May be used to mask a brief transition.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
delay: Delay before updating.
|
||||||
|
"""
|
||||||
|
self._begin_batch()
|
||||||
|
|
||||||
|
def end_batch() -> None:
|
||||||
|
"""Re-enable updates, and refresh screen."""
|
||||||
|
self.screen.refresh()
|
||||||
|
self._end_batch()
|
||||||
|
|
||||||
|
self.set_timer(delay, end_batch, name="_delay_update")
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def _context(self) -> Generator[None, None, None]:
|
def _context(self) -> Generator[None, None, None]:
|
||||||
"""Context manager to set ContextVars."""
|
"""Context manager to set ContextVars."""
|
||||||
@@ -3504,7 +3521,8 @@ class App(Generic[ReturnType], DOMNode):
|
|||||||
try:
|
try:
|
||||||
if renderable is None:
|
if renderable is None:
|
||||||
return
|
return
|
||||||
|
if self._batch_count:
|
||||||
|
return
|
||||||
if (
|
if (
|
||||||
self._running
|
self._running
|
||||||
and not self._closed
|
and not self._closed
|
||||||
|
|||||||
@@ -1231,6 +1231,7 @@ class CommandPalette(SystemModalScreen[None]):
|
|||||||
# decide what to do with it (hopefully it'll run it).
|
# decide what to do with it (hopefully it'll run it).
|
||||||
self._cancel_gather_commands()
|
self._cancel_gather_commands()
|
||||||
self.app.post_message(CommandPalette.Closed(option_selected=True))
|
self.app.post_message(CommandPalette.Closed(option_selected=True))
|
||||||
|
self.app._delay_update()
|
||||||
self.dismiss()
|
self.dismiss()
|
||||||
self.app.call_later(self._selected_command.command)
|
self.app.call_later(self._selected_command.command)
|
||||||
|
|
||||||
|
|||||||
@@ -1310,7 +1310,6 @@ class Screen(Generic[ScreenResultType], Widget):
|
|||||||
"""Called by App when the screen is resized."""
|
"""Called by App when the screen is resized."""
|
||||||
if self.stack_updates:
|
if self.stack_updates:
|
||||||
self._refresh_layout(size)
|
self._refresh_layout(size)
|
||||||
self._compositor_refresh()
|
|
||||||
|
|
||||||
def _on_screen_resume(self) -> None:
|
def _on_screen_resume(self) -> None:
|
||||||
"""Screen has resumed."""
|
"""Screen has resumed."""
|
||||||
@@ -1331,6 +1330,7 @@ class Screen(Generic[ScreenResultType], Widget):
|
|||||||
self.set_focus(widget)
|
self.set_focus(widget)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
self._compositor_refresh()
|
||||||
self.app.stylesheet.update(self)
|
self.app.stylesheet.update(self)
|
||||||
self._refresh_layout(size)
|
self._refresh_layout(size)
|
||||||
|
|
||||||
|
|||||||
@@ -59,5 +59,4 @@ async def test_command_dismiss():
|
|||||||
await pilot.press("ctrl+p", *"modal quit", "enter")
|
await pilot.press("ctrl+p", *"modal quit", "enter")
|
||||||
await pilot.pause()
|
await pilot.pause()
|
||||||
await pilot.press("enter")
|
await pilot.press("enter")
|
||||||
await pilot.pause()
|
|
||||||
assert app.check_quit_called
|
assert app.check_quit_called
|
||||||
|
|||||||
Reference in New Issue
Block a user