From be5a67e90360c810059530503bd29a8ec2c3a992 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Tue, 31 Jan 2023 12:13:25 +0100 Subject: [PATCH] fix auto width glitch --- src/textual/widgets/_input.py | 1 + .../__snapshots__/test_snapshots.ambr | 160 ++++++++++++++++++ tests/snapshot_tests/test_snapshots.py | 6 + 3 files changed, 167 insertions(+) diff --git a/src/textual/widgets/_input.py b/src/textual/widgets/_input.py index b09b96310..333b8e9fe 100644 --- a/src/textual/widgets/_input.py +++ b/src/textual/widgets/_input.py @@ -255,6 +255,7 @@ class Input(Widget, can_focus=True): return self._position_to_cell(len(self.value)) + 1 def render(self) -> RenderableType: + self.view_position = self.view_position if not self.value: placeholder = Text(self.placeholder, justify="left") placeholder.stylize(self.get_component_rich_style("input--placeholder")) diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr index 90173650b..d347bcc03 100644 --- a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr +++ b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr @@ -1,3 +1,163 @@ +# name: test_auto_width_input + ''' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + InputWidthAutoApp + + + + + + + + + + InputWidthAutoApp + ▔▔▔▔▔▔▔▔▔▔ + Hello + ▁▁▁▁▁▁▁▁▁▁ + + + + + + + + + + + + + + + + + + + + + + + + + ''' +# --- # name: test_buttons_render ''' diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index bdad3bf53..a2a8447ba 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -198,3 +198,9 @@ def test_demo(snap_compare): def test_label_widths(snap_compare): """Test renderable widths are calculate correctly.""" assert snap_compare(SNAPSHOT_APPS_DIR / "label_widths.py") + + +def test_auto_width_input(snap_compare): + assert snap_compare( + SNAPSHOT_APPS_DIR / "auto_width_input.py", press=["tab", *"Hello"] + )