From 1909ba42d6ac5250bb120a01bf3756be9a6594de Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Mon, 26 Feb 2024 15:42:08 +0000 Subject: [PATCH 1/2] potential fix --- src/textual/layouts/grid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/textual/layouts/grid.py b/src/textual/layouts/grid.py index d38c74a7d7..077b905074 100644 --- a/src/textual/layouts/grid.py +++ b/src/textual/layouts/grid.py @@ -211,7 +211,7 @@ def apply_height_limits(widget: Widget, height: int) -> int: widget.get_content_height( size, viewport, - column_width - parent.styles.grid_gutter_vertical, + column_width, ) + widget.styles.gutter.height, ) From f2ff9ca6fbd704256dc6db161b9636235bf79253 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Gir=C3=A3o=20Serr=C3=A3o?= <5621605+rodrigogiraoserrao@users.noreply.github.com> Date: Mon, 26 Feb 2024 16:00:41 +0000 Subject: [PATCH 2/2] Add test. --- CHANGELOG.md | 1 + .../__snapshots__/test_snapshots.ambr | 91 +++++++++++++++++++ .../pretty_grid_gutter_interaction.py | 41 +++++++++ tests/snapshot_tests/test_snapshots.py | 11 ++- 4 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 tests/snapshot_tests/snapshot_apps/pretty_grid_gutter_interaction.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c86abcb13..9d7973f738 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Simplified tree-sitter highlight queries for HTML, which also seems to fix segfault issue https://github.com/Textualize/textual/pull/4195 - Fixed `DirectoryTree.path` no longer reacting to new values https://github.com/Textualize/textual/issues/4208 - Fixed content size cache with Pretty widget https://github.com/Textualize/textual/pull/4211 +- Fixed `grid-gutter` interaction with Pretty widget https://github.com/Textualize/textual/pull/4219 ## [0.52.1] - 2024-02-20 diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr index f31002578f..3feaf66053 100644 --- a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr +++ b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr @@ -27297,6 +27297,97 @@ ''' # --- +# name: test_pretty_grid_gutter_interaction + ''' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + MyApp + + + + + + + + + + ['This is a string that has some chars'] + + This should be 1 cell away from ^ + + + + + + + + + ''' +# --- # name: test_print_capture ''' diff --git a/tests/snapshot_tests/snapshot_apps/pretty_grid_gutter_interaction.py b/tests/snapshot_tests/snapshot_apps/pretty_grid_gutter_interaction.py new file mode 100644 index 0000000000..59c768d57b --- /dev/null +++ b/tests/snapshot_tests/snapshot_apps/pretty_grid_gutter_interaction.py @@ -0,0 +1,41 @@ +"""App used as regression test for https://github.com/Textualize/textual/pull/4219.""" + +from __future__ import annotations + +from textual.app import App, ComposeResult +from textual.containers import Grid +from textual.widgets import Pretty, Label + + +class MyGrid(Grid): + """A simple grid with 2 columns and 2 rows.""" + + +class MyApp(App[None]): + DEFAULT_CSS = """ + MyGrid { + height: auto; + grid-rows: auto; + grid-size: 2; + grid-gutter: 1; + background: green; + } + + Pretty { + background: red; + } + + Label { + background: blue; + } +""" + + def compose(self) -> ComposeResult: + with MyGrid(): + yield Pretty(["This is a string that has some chars"]) + yield Label() + yield Label("This should be 1 cell away from ^") + + +if __name__ == "__main__": + MyApp().run() diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index 8adff1659f..281ec6d6ea 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -762,7 +762,9 @@ async def run_before(pilot) -> None: pilot.app.screen.query_one(Input).cursor_blink = False await pilot.app.screen.workers.wait_for_complete() - assert snap_compare(SNAPSHOT_APPS_DIR / "command_palette_discovery.py", run_before=run_before) + assert snap_compare( + SNAPSHOT_APPS_DIR / "command_palette_discovery.py", run_before=run_before + ) # --- textual-dev library preview tests --- @@ -1052,3 +1054,10 @@ def test_input_percentage_width(snap_compare): """Check percentage widths work correctly.""" # https://github.com/Textualize/textual/issues/3721 assert snap_compare(SNAPSHOT_APPS_DIR / "input_percentage_width.py") + + +def test_pretty_grid_gutter_interaction(snap_compare): + """Regression test for https://github.com/Textualize/textual/pull/4219.""" + assert snap_compare( + SNAPSHOT_APPS_DIR / "pretty_grid_gutter_interaction.py", terminal_size=(81, 7) + )