diff --git a/CHANGELOG.md b/CHANGELOG.md index c3e3694a5..26d7a0dd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Added a workaround for an apparent Windows Terminal paste issue https://github.com/Textualize/textual/issues/1661 - Fixes issue with renderable width calculation https://github.com/Textualize/textual/issues/1685 - Fixed issue with app not processing Paste event https://github.com/Textualize/textual/issues/1666 +- Fixed glitch with view position with auto width inputs https://github.com/Textualize/textual/issues/1693 ## [0.10.1] - 2023-01-20 diff --git a/src/textual/widgets/_input.py b/src/textual/widgets/_input.py index 5af98629b..ee47b3801 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/snapshot_apps/auto_width_input.py b/tests/snapshot_tests/snapshot_apps/auto_width_input.py new file mode 100644 index 000000000..35cc3b2ec --- /dev/null +++ b/tests/snapshot_tests/snapshot_apps/auto_width_input.py @@ -0,0 +1,22 @@ +from textual.app import App, ComposeResult +from textual.containers import Vertical +from textual.widgets import Header, Footer, Label, Input + + +class InputWidthAutoApp(App[None]): + + CSS = """ + Input.auto { + width: auto; + max-width: 100%; + } + """ + + def compose(self) -> ComposeResult: + yield Header() + yield Input(placeholder="This has auto width", classes="auto") + yield Footer() + + +if __name__ == "__main__": + InputWidthAutoApp().run() 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"] + )