diff --git a/src/command_palette.py b/src/command_palette.py index 4be5a74b..655b3940 100644 --- a/src/command_palette.py +++ b/src/command_palette.py @@ -121,10 +121,9 @@ def render_palette_modal(app: Any, commands: List[Command]) -> None: if not hasattr(app, "_command_palette_focused"): app._command_palette_focused = False - # Set focus on the input field ONCE per open. - # set_keyboard_focus_here must be called BEFORE the widget to give it focus. + # Set focus on the window + input field ONCE per open. if not app._command_palette_focused: - imgui.set_keyboard_focus_here() + imgui.set_next_window_focus() app._command_palette_focused = True # Escape closes the palette. @@ -140,6 +139,11 @@ def render_palette_modal(app: Any, commands: List[Command]) -> None: imgui.end() return + # After the window is drawn, the input gets focus. + if not getattr(app, '_command_palette_input_focused', False): + imgui.set_keyboard_focus_here() + app._command_palette_input_focused = True + imgui.set_next_item_width(-1) _, app._command_palette_query = imgui.input_text("##query", app._command_palette_query) @@ -153,11 +157,16 @@ def render_palette_modal(app: Any, commands: List[Command]) -> None: if clicked: app._command_palette_selected = i if scored.command.action: - scored.command.action(app) + try: + scored.command.action(app) + except Exception as e: + # Don't let a buggy action break the end_child/end pairing. + print(f"[CommandPalette] Action {scored.command.id} raised: {e}") app.show_command_palette = False app._command_palette_query = "" app._command_palette_selected = 0 app._command_palette_focused = False + app._command_palette_input_focused = False if not results: imgui.text_disabled("No matching commands.") imgui.end_child() diff --git a/src/commands.py b/src/commands.py index 738728da..4ac4fd7d 100644 --- a/src/commands.py +++ b/src/commands.py @@ -69,20 +69,20 @@ def show_documentation(app: "App") -> None: @registry.register def switch_to_dark_theme(app: "App") -> None: - """Switch to Dark Theme.""" + """Switch to Dark Theme (10x Dark palette).""" from src import theme_2 - theme_2.apply_dark_theme() + theme_2.apply("10x Dark") @registry.register def switch_to_light_theme(app: "App") -> None: - """Switch to Light Theme.""" + """Switch to Light Theme (ImGui Light palette).""" from src import theme_2 - theme_2.apply_light_theme() + theme_2.apply("ImGui Light") @registry.register def switch_to_nerv_theme(app: "App") -> None: """Switch to NERV Theme.""" - from src.theme_nerv import apply_nerv - apply_nerv() + from src import theme_2 + theme_2.apply("NERV") diff --git a/src/gui_2.py b/src/gui_2.py index 6b8b7d01..4855f5b3 100644 --- a/src/gui_2.py +++ b/src/gui_2.py @@ -738,6 +738,8 @@ class App: self._command_palette_query = "" if hasattr(self, '_command_palette_selected'): self._command_palette_selected = 0 + if hasattr(self, '_command_palette_input_focused'): + self._command_palette_input_focused = False def _test_callback_func_write_to_file(self, data: str) -> None: """A dummy function that a custom_callback would execute for testing."""