Private
Public Access
0
0

fix(palette): auto-focus input via set_next_window_focus + apply(theme) + try/except for actions

Added imgui.set_next_window_focus() on open so the palette window itself gets focus. The input field then gets focus on the next drawn widget. Wrapped action calls in try/except so a buggy command does not break the imgui.end_child/end pairing (was causing IM_ASSERT crash). Fixed theme_2 calls: apply_dark_theme and apply_light_theme do not exist; use theme_2.apply(palette_name). switch_to_dark_theme uses apply 10x Dark. switch_to_light_theme uses apply ImGui Light. switch_to_nerv_theme uses apply NERV instead of apply_nerv() from src.theme_nerv.
This commit is contained in:
2026-06-02 22:33:05 -04:00
parent 592f816caf
commit 9cfd7b0d12
3 changed files with 21 additions and 10 deletions
+13 -4
View File
@@ -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()