mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
@@ -899,7 +899,7 @@ class App(Generic[ReturnType], DOMNode):
|
||||
self.log.system(f"{self.screen} is active")
|
||||
return previous_screen
|
||||
|
||||
def set_focus(self, widget: Widget | None, scroll_visible: bool = False) -> None:
|
||||
def set_focus(self, widget: Widget | None, scroll_visible: bool = True) -> None:
|
||||
"""Focus (or unfocus) a widget. A focused widget will receive key events first.
|
||||
|
||||
Args:
|
||||
|
||||
@@ -300,8 +300,11 @@ class Screen(Widget):
|
||||
except errors.NoWidget:
|
||||
self.app.set_focus(None)
|
||||
else:
|
||||
if isinstance(event, events.MouseDown) and widget.can_focus:
|
||||
self.app.set_focus(widget)
|
||||
if isinstance(event, events.MouseUp) and widget.can_focus:
|
||||
if self.app.focused is not widget:
|
||||
self.app.set_focus(widget)
|
||||
event.stop()
|
||||
return
|
||||
event.style = self.get_style_at(event.screen_x, event.screen_y)
|
||||
if widget is self:
|
||||
event.set_forwarded()
|
||||
|
||||
@@ -1435,9 +1435,14 @@ class Widget(DOMNode):
|
||||
self._layout_required = False
|
||||
screen.post_message_no_wait(messages.Layout(self))
|
||||
|
||||
def focus(self) -> None:
|
||||
"""Give input focus to this widget."""
|
||||
self.app.set_focus(self)
|
||||
def focus(self, scroll_visible: bool = True) -> None:
|
||||
"""Give focus to this widget.
|
||||
|
||||
Args:
|
||||
scroll_visible (bool, optional): Scroll parent to make this widget
|
||||
visible. Defaults to True.
|
||||
"""
|
||||
self.app.set_focus(self, scroll_visible=scroll_visible)
|
||||
|
||||
def capture_mouse(self, capture: bool = True) -> None:
|
||||
"""Capture (or release) the mouse.
|
||||
|
||||
Reference in New Issue
Block a user