Skip to content

Commit d1bc062

Browse files
committed
fix: restore editor focus after hiding project view
1 parent cb5f73e commit d1bc062

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

tests/test_ui_ux_accessibility.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import pytest
66
from PySide6.QtWidgets import QApplication
7+
from unittest.mock import patch
78

89
from ui.main_window import MainWindow
910
from ui.settings_dialog import SettingsDialog
@@ -68,6 +69,27 @@ def test_main_window_toolbar_ux_and_a11y(qapp):
6869
window.close()
6970

7071

72+
def test_hiding_project_view_restores_editor_focus(qapp):
73+
"""Der Fokus darf nicht im ausgeblendeten Projektbaum verbleiben."""
74+
with patch("features.terminal.TerminalWidget._start_shell", lambda self: None):
75+
window = MainWindow()
76+
try:
77+
window.show()
78+
qapp.processEvents()
79+
editor = window.tab_widget.current_tab().editor
80+
window.project_view.tree.setFocus()
81+
qapp.processEvents()
82+
assert window.project_view.tree.hasFocus()
83+
84+
window._toggle_project_view()
85+
qapp.processEvents()
86+
87+
assert not window.project_view.isVisible()
88+
assert editor.hasFocus()
89+
finally:
90+
window.close()
91+
92+
7193
def test_tab_widget_ux_tooltips_and_a11y(qapp, tmp_path):
7294
"""Prüft Tab-Tooltips mit echtem Pfad und Accessible-Attribute."""
7395
tabs = TabWidget()

ui/main_window.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,16 @@ def _open_file_from_project(self, file_path):
737737

738738
def _toggle_project_view(self):
739739
"""Blendet den Projektbaum ein/aus."""
740-
self.project_view.setVisible(not self.project_view.isVisible())
740+
was_visible = self.project_view.isVisible()
741+
self.project_view.setVisible(not was_visible)
742+
if was_visible:
743+
self._focus_active_editor()
744+
745+
def _focus_active_editor(self):
746+
"""Setzt den Tastaturfokus auf den aktiven Editor zurück."""
747+
tab = self.tab_widget.current_tab()
748+
if tab and tab.editor:
749+
tab.editor.setFocus()
741750

742751
def _toggle_terminal(self):
743752
"""Blendet das untere Panel ein/aus und wechselt zum Terminal-Tab."""

0 commit comments

Comments
 (0)