diff --git a/datashuttle/tui/custom_widgets.py b/datashuttle/tui/custom_widgets.py index 5ab548fca..afd0d90ec 100644 --- a/datashuttle/tui/custom_widgets.py +++ b/datashuttle/tui/custom_widgets.py @@ -12,6 +12,7 @@ from collections.abc import Iterable from textual import events + from textual.events import MouseMove from textual.validation import Validator from datashuttle.tui.app import TuiApp @@ -146,6 +147,15 @@ def __init__( self.mainwindow = mainwindow + def on_mouse_move(self, event: MouseMove) -> None: + """Handle focus for this widget. + + Explicitly grab focus when mouse moves into widget so that + keyboard shortcuts work without having to click the folder. + """ + if not self.has_focus: # type: ignore + self.focus() + def filter_paths(self, paths: Iterable[Path]) -> Iterable[Path]: """Filter out all hidden folders and files from CustomDirectoryTree display.