@@ -9,7 +9,7 @@ from PyQt6.QtWidgets import ( |
| 9 | 9 | QWidget, QToolBar, QLabel, QComboBox, QLineEdit, |
| 10 | 10 | QPushButton, QHBoxLayout, QVBoxLayout, QTreeView, |
| 11 | 11 | QHeaderView, QSizePolicy, QAbstractItemView, |
| 12 | | - QMenu |
| 12 | + QMenu, QApplication |
| 13 | 13 | ) |
| 14 | 14 | |
| 15 | 15 | from ..core import Icons, AppConfig, Styles |
@@ -338,19 +338,36 @@ class LocalFilePane(FilePane): |
| 338 | 338 | # Connect double-click handler |
| 339 | 339 | self.tree_view.doubleClicked.connect(self._on_double_click) |
| 340 | 340 | |
| 341 | + # Set focus policy |
| 342 | + self.tree_view.setFocusPolicy(Qt.FocusPolicy.StrongFocus) |
| 343 | + |
| 341 | 344 | def _on_double_click(self, index: QModelIndex): |
| 342 | 345 | """Handle double-click on local file.""" |
| 343 | 346 | if self.model.isDir(index): |
| 347 | + # Store current focus widget |
| 348 | + focus_widget = QApplication.focusWidget() |
| 349 | + |
| 344 | 350 | self.tree_view.setRootIndex(index) |
| 345 | 351 | self.set_path(self.model.filePath(index)) |
| 346 | 352 | |
| 353 | + # Restore focus |
| 354 | + if focus_widget: |
| 355 | + focus_widget.setFocus() |
| 356 | + |
| 347 | 357 | def navigate_up(self): |
| 348 | 358 | """Navigate up one directory.""" |
| 359 | + # Store current focus widget |
| 360 | + focus_widget = QApplication.focusWidget() |
| 361 | + |
| 349 | 362 | current = self.tree_view.rootIndex() |
| 350 | 363 | parent = self.model.parent(current) |
| 351 | 364 | if parent.isValid(): |
| 352 | 365 | self.tree_view.setRootIndex(parent) |
| 353 | 366 | self.set_path(self.model.filePath(parent)) |
| 367 | + |
| 368 | + # Restore focus |
| 369 | + if focus_widget: |
| 370 | + focus_widget.setFocus() |
| 354 | 371 | |
| 355 | 372 | def navigate_home(self): |
| 356 | 373 | """Navigate to home directory.""" |
@@ -358,10 +375,6 @@ class LocalFilePane(FilePane): |
| 358 | 375 | self.tree_view.setRootIndex(home_index) |
| 359 | 376 | self.set_path(QDir.homePath()) |
| 360 | 377 | |
| 361 | | - # Restore focus after navigation |
| 362 | | - self.window().raise_() |
| 363 | | - self.window().activateWindow() |
| 364 | | - |
| 365 | 378 | def get_selected_items(self) -> List[Tuple[str, bool]]: |
| 366 | 379 | """Get selected items as list of (path, is_dir) tuples.""" |
| 367 | 380 | items = [] |
@@ -422,6 +435,9 @@ class RemoteFilePane(FilePane): |
| 422 | 435 | # Connect double-click handler |
| 423 | 436 | self.tree_view.doubleClicked.connect(self._on_double_click) |
| 424 | 437 | |
| 438 | + # Set focus policy |
| 439 | + self.tree_view.setFocusPolicy(Qt.FocusPolicy.StrongFocus) |
| 440 | + |
| 425 | 441 | # Start disabled until connected |
| 426 | 442 | self.setEnabled(False) |
| 427 | 443 | |
@@ -440,17 +456,31 @@ class RemoteFilePane(FilePane): |
| 440 | 456 | def _on_double_click(self, index: QModelIndex): |
| 441 | 457 | """Handle double-click on remote file.""" |
| 442 | 458 | if self.model.isDir(index): |
| 459 | + # Store current focus widget |
| 460 | + focus_widget = QApplication.focusWidget() |
| 461 | + |
| 443 | 462 | path = self.model.filePath(index) |
| 444 | 463 | self.model.set_root_path(path) |
| 445 | 464 | self.set_path(path) |
| 446 | 465 | |
| 466 | + # Restore focus |
| 467 | + if focus_widget: |
| 468 | + focus_widget.setFocus() |
| 469 | + |
| 447 | 470 | def navigate_up(self): |
| 448 | 471 | """Navigate up one directory.""" |
| 472 | + # Store current focus widget |
| 473 | + focus_widget = QApplication.focusWidget() |
| 474 | + |
| 449 | 475 | current_path = self.model.rootPath() |
| 450 | 476 | if current_path and current_path != "/": |
| 451 | 477 | parent_path = os.path.dirname(current_path) |
| 452 | 478 | self.model.set_root_path(parent_path) |
| 453 | 479 | self.set_path(parent_path) |
| 480 | + |
| 481 | + # Restore focus |
| 482 | + if focus_widget: |
| 483 | + focus_widget.setFocus() |
| 454 | 484 | |
| 455 | 485 | def navigate_home(self): |
| 456 | 486 | """Navigate to home directory.""" |
@@ -465,10 +495,6 @@ class RemoteFilePane(FilePane): |
| 465 | 495 | self.model.set_root_path("/") |
| 466 | 496 | self.set_path("/") |
| 467 | 497 | |
| 468 | | - # Restore focus after navigation |
| 469 | | - self.window().raise_() |
| 470 | | - self.window().activateWindow() |
| 471 | | - |
| 472 | 498 | def get_selected_items(self) -> List[Tuple[str, bool, str]]: |
| 473 | 499 | """Get selected items as list of (path, is_dir, name) tuples.""" |
| 474 | 500 | items = [] |