Skip to content

Commit a7bacbb

Browse files
committed
Only apply select_on_focus in Input if the focus event wasn't produced from an app focus event.
1 parent b2d9dc3 commit a7bacbb

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/textual/app.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4052,7 +4052,9 @@ def _watch_app_focus(self, focus: bool) -> None:
40524052
# ...settle focus back on that widget.
40534053
# Don't scroll the newly focused widget, as this can be quite jarring
40544054
self.screen.set_focus(
4055-
self._last_focused_on_app_blur, scroll_visible=False
4055+
self._last_focused_on_app_blur,
4056+
scroll_visible=False,
4057+
from_app_focus=True,
40564058
)
40574059
except NoScreen:
40584060
pass

src/textual/events.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,10 @@ def __init__(self, from_app_focus: bool = False) -> None:
734734
self.from_app_focus = from_app_focus
735735
super().__init__()
736736

737+
def __rich_repr__(self) -> rich.repr.Result:
738+
yield from super().__rich_repr__()
739+
yield "from_app_focus", self.from_app_focus
740+
737741

738742
class Blur(Event, bubble=False):
739743
"""Sent when a widget is blurred (un-focussed).

src/textual/widgets/_input.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ def _on_blur(self, event: Blur) -> None:
641641

642642
def _on_focus(self, event: Focus) -> None:
643643
self._restart_blink()
644-
if self.select_on_focus:
644+
if self.select_on_focus and not event.from_app_focus:
645645
self.selection = Selection(0, len(self.value))
646646
self.app.cursor_position = self.cursor_screen_offset
647647
self._suggestion = ""

0 commit comments

Comments
 (0)