Source code for simvx.ide.keybindings

"""Default IDE keybindings (VS Code-like)."""

from typing import TYPE_CHECKING

from simvx.core import DeviceButton, InputBinding, Key

if TYPE_CHECKING:
    from simvx.core.shortcuts import ShortcutManager


# Binding table: (binding, action_name). A binding holding a modifier is exact.
DEFAULT_BINDINGS: list[tuple[InputBinding | DeviceButton, str]] = [
    # File operations
    (Key.CTRL + Key.N, "file.new"),
    (Key.CTRL + Key.O, "file.open"),
    (Key.CTRL + Key.S, "file.save"),
    (Key.CTRL + Key.SHIFT + Key.S, "file.save_as"),
    (Key.CTRL + Key.W, "file.close"),
    # Edit operations
    (Key.CTRL + Key.Z, "edit.undo"),
    (Key.CTRL + Key.SHIFT + Key.Z, "edit.redo"),
    (Key.CTRL + Key.X, "edit.cut"),
    (Key.CTRL + Key.C, "edit.copy"),
    (Key.CTRL + Key.V, "edit.paste"),
    (Key.CTRL + Key.A, "edit.select_all"),
    (Key.CTRL + Key.SLASH, "edit.toggle_comment"),
    (Key.CTRL + Key.SHIFT + Key.K, "edit.delete_line"),
    (Key.CTRL + Key.D, "edit.select_next_occurrence"),
    # Line operations
    (Key.CTRL + Key.SHIFT + Key.D, "edit.duplicate_line"),
    (Key.ALT + Key.UP, "edit.move_line_up"),
    (Key.ALT + Key.DOWN, "edit.move_line_down"),
    # Folding
    (Key.CTRL + Key.SHIFT + Key.LEFT_BRACKET, "edit.fold"),
    (Key.CTRL + Key.SHIFT + Key.RIGHT_BRACKET, "edit.unfold"),
    # Find / Replace
    (Key.CTRL + Key.F, "find.find"),
    (Key.CTRL + Key.H, "find.replace"),
    (Key.CTRL + Key.SHIFT + Key.F, "find.find_in_files"),
    # Navigation
    (Key.CTRL + Key.G, "navigate.goto_line"),
    (Key.CTRL + Key.P, "navigate.goto_file"),
    (Key.CTRL + Key.SHIFT + Key.P, "navigate.command_palette"),
    (Key.F12, "navigate.goto_definition"),
    (Key.SHIFT + Key.F12, "navigate.find_references"),
    (Key.CTRL + Key.SHIFT + Key.O, "navigate.goto_symbol"),
    # Bookmarks
    (Key.CTRL + Key.F2, "navigate.toggle_bookmark"),
    (Key.F2, "navigate.next_bookmark"),
    (Key.SHIFT + Key.F2, "navigate.prev_bookmark"),
    # History
    (Key.ALT + Key.LEFT, "navigate.history_back"),
    (Key.ALT + Key.RIGHT, "navigate.history_forward"),
    # View
    (Key.CTRL + Key.B, "view.toggle_sidebar"),
    (Key.CTRL + Key.J, "view.toggle_bottom_panel"),
    (Key.CTRL + Key.GRAVE_ACCENT, "view.toggle_terminal"),
    # Run / Debug
    (Key.F5, "run.run"),
    (Key.CTRL + Key.F5, "run.run_no_debug"),
    (Key.F9, "debug.toggle_breakpoint"),
    (Key.F10, "debug.step_over"),
    (Key.F11, "debug.step_into"),
    (Key.SHIFT + Key.F11, "debug.step_out"),
    (Key.SHIFT + Key.F5, "debug.stop"),
    (Key.CTRL + Key.SHIFT + Key.F5, "debug.restart"),
    # Editor
    (Key.CTRL + Key.SHIFT + Key.L, "edit.format_document"),
    # Zoom
    (Key.CTRL + Key.EQUAL, "view.zoom_in"),
    (Key.CTRL + Key.MINUS, "view.zoom_out"),
]


[docs] def register_keybindings(shortcuts: ShortcutManager, actions: dict): """Register all default bindings. `actions` maps action names to callables.""" for binding, action_name in DEFAULT_BINDINGS: callback = actions.get(action_name) if callback: shortcuts.register(action_name, binding, callback)