Only apply select_on_focus in Input if the focus event wasn't produced from an app focus event.

This commit is contained in:
Darren Burns 2024-12-12 13:20:23 +00:00 committed by Will McGugan
parent 98432b2fd9
commit 15e77c8150
3 changed files with 8 additions and 2 deletions

View file

@ -4052,7 +4052,9 @@ class App(Generic[ReturnType], DOMNode):
# ...settle focus back on that widget.
# Don't scroll the newly focused widget, as this can be quite jarring
self.screen.set_focus(
self._last_focused_on_app_blur, scroll_visible=False
self._last_focused_on_app_blur,
scroll_visible=False,
from_app_focus=True,
)
except NoScreen:
pass

View file

@ -736,6 +736,10 @@ class Focus(Event, bubble=False):
self.from_app_focus = from_app_focus
super().__init__()
def __rich_repr__(self) -> rich.repr.Result:
yield from super().__rich_repr__()
yield "from_app_focus", self.from_app_focus
class Blur(Event, bubble=False):
"""Sent when a widget is blurred (un-focussed).

View file

@ -641,7 +641,7 @@ class Input(ScrollView):
def _on_focus(self, event: Focus) -> None:
self._restart_blink()
if self.select_on_focus:
if self.select_on_focus and not event.from_app_focus:
self.selection = Selection(0, len(self.value))
self.app.cursor_position = self.cursor_screen_offset
self._suggestion = ""