diff --git a/CHANGELOG.md b/CHANGELOG.md index 187c62abe0..ca172cb486 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed - Fixed infinite loop in `Widget.anchor` https://github.com/Textualize/textual/pull/5290 +- Fixed delayed App Resize event https://github.com/Textualize/textual/pull/5296 ## [0.87.1] - 2024-11-24 diff --git a/src/textual/app.py b/src/textual/app.py index 9911eb29dc..d54f5f49f7 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -3067,6 +3067,9 @@ async def invoke_ready_callback() -> None: try: try: await self._dispatch_message(events.Compose()) + await self._dispatch_message( + events.Resize.from_dimensions(self.size, None) + ) default_screen = self.screen self.stylesheet.apply(self) await self._dispatch_message(events.Mount()) diff --git a/src/textual/drivers/linux_driver.py b/src/textual/drivers/linux_driver.py index 510b0992f0..7e04f4cf26 100644 --- a/src/textual/drivers/linux_driver.py +++ b/src/textual/drivers/linux_driver.py @@ -216,8 +216,6 @@ def _stop_again(*_) -> None: loop = asyncio.get_running_loop() def send_size_event() -> None: - if self._in_band_window_resize: - return terminal_size = self._get_terminal_size() width, height = terminal_size textual_size = Size(width, height) @@ -231,7 +229,8 @@ def send_size_event() -> None: self._writer_thread.start() def on_terminal_resize(signum, stack) -> None: - send_size_event() + if not self._in_band_window_resize: + send_size_event() signal.signal(signal.SIGWINCH, on_terminal_resize) diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots/test_app_resize_order.svg b/tests/snapshot_tests/__snapshots__/test_snapshots/test_app_resize_order.svg new file mode 100644 index 0000000000..88b119eec7 --- /dev/null +++ b/tests/snapshot_tests/__snapshots__/test_snapshots/test_app_resize_order.svg @@ -0,0 +1,153 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SCApp + + + + + + + + + + ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ + + + + + + + + + + +                                    BAR                                      + + + + + + + + + + + +┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + + + diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index 19b2155364..d87c730697 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -2749,3 +2749,45 @@ async def run_before(pilot: Pilot) -> None: await pilot.click("Select") snap_compare(TallSelectApp(), run_before=run_before) + + +def test_app_resize_order(snap_compare): + """Regression test for https://github.com/Textualize/textual/issues/5284 + You should see a placeholder with text "BAR", focused and scrolled down so it fills the screen. + """ + + class FocusPlaceholder(Placeholder, can_focus=True): + pass + + class NarrowScreen(Screen): + AUTO_FOCUS = "#bar" + + def compose(self) -> ComposeResult: + yield FocusPlaceholder("FOO", id="foo") + yield FocusPlaceholder("BAR", id="bar") + + class SCApp(App): + CSS = """ + Placeholder:focus { + border: heavy white; + } + #foo { + height: 24; + } + #bar { + height: 1fr; + } + + .narrow #bar { + height: 100%; + } + + """ + + def on_mount(self) -> None: + self.push_screen(NarrowScreen()) + + def on_resize(self) -> None: + self.add_class("narrow") + + snap_compare(SCApp())