From d4be9ac080240917675e86dfbf97f27151105f94 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Tue, 6 Jun 2023 10:41:20 +0100 Subject: [PATCH 1/3] Make cursor position watch private Also remove the parameter that wasn't being used anyway. --- src/textual/widgets/_input.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/textual/widgets/_input.py b/src/textual/widgets/_input.py index 1c1ca124ae..b66613031b 100644 --- a/src/textual/widgets/_input.py +++ b/src/textual/widgets/_input.py @@ -282,7 +282,7 @@ def validate_view_position(self, view_position: int) -> int: new_view_position = max(0, min(view_position, self.cursor_width - width)) return new_view_position - def watch_cursor_position(self, cursor_position: int) -> None: + def _watch_cursor_position(self) -> None: width = self.content_size.width if width == 0: # If the input has no width the view position can't be elsewhere. From 552d381c585b6f9078b36c1e2fa1befb5974e075 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Tue, 6 Jun 2023 10:42:16 +0100 Subject: [PATCH 2/3] Make the value watcher private --- src/textual/widgets/_input.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/textual/widgets/_input.py b/src/textual/widgets/_input.py index b66613031b..f99007c226 100644 --- a/src/textual/widgets/_input.py +++ b/src/textual/widgets/_input.py @@ -299,7 +299,7 @@ def _watch_cursor_position(self) -> None: else: self.view_position = self.view_position - async def watch_value(self, value: str) -> None: + async def _watch_value(self, value: str) -> None: self._suggestion = "" if self.suggester and value: self.run_worker(self.suggester._get_suggestion(self, value)) From 235fdc2c488fb3f33996b0dacbef338bc98ca3ef Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Tue, 6 Jun 2023 10:47:16 +0100 Subject: [PATCH 3/3] Remove dead code from Input._on_key The branch being removed here seems to be trying to handle keyboard bindings before handling the raw keyboard event. However, in the unit tests, even when a binding is pressed, this code doesn't get called. I strongly suspect this is code that predates changes that were made some time ago in respect to the order in which bindings were processed and their relationship to keystrokes. After removing this all tests are passing just fine and hand-testing `Input` (especially in the demo, for example, both non-password and password incarnations) shows no problems either. All evidence suggests that #2737 was incapable of hitting that branch of code because it just could not be hit these days. --- src/textual/widgets/_input.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/textual/widgets/_input.py b/src/textual/widgets/_input.py index f99007c226..daf298e7aa 100644 --- a/src/textual/widgets/_input.py +++ b/src/textual/widgets/_input.py @@ -400,12 +400,7 @@ async def _on_key(self, event: events.Key) -> None: if self.cursor_blink: self.blink_timer.reset() - # Do key bindings first - if await self.handle_key(event): - event.prevent_default() - event.stop() - return - elif event.is_printable: + if event.is_printable: event.stop() assert event.character is not None self.insert_text_at_cursor(event.character)