Source code for simvx.ide.keybindings

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


from __future__ import annotations

import logging
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from simvx.core.shortcuts import ShortcutManager

log = logging.getLogger(__name__)


# Binding table: (shortcut_string, action_name)
DEFAULT_BINDINGS = [
    # File operations
    ("Ctrl+N", "file.new"),
    ("Ctrl+O", "file.open"),
    ("Ctrl+S", "file.save"),
    ("Ctrl+Shift+S", "file.save_as"),
    ("Ctrl+W", "file.close"),
    # Edit operations
    ("Ctrl+Z", "edit.undo"),
    ("Ctrl+Shift+Z", "edit.redo"),
    ("Ctrl+X", "edit.cut"),
    ("Ctrl+C", "edit.copy"),
    ("Ctrl+V", "edit.paste"),
    ("Ctrl+A", "edit.select_all"),
    ("Ctrl+/", "edit.toggle_comment"),
    ("Ctrl+Shift+K", "edit.delete_line"),
    ("Ctrl+D", "edit.select_next_occurrence"),
    # Line operations
    ("Ctrl+Shift+D", "edit.duplicate_line"),
    ("Alt+Up", "edit.move_line_up"),
    ("Alt+Down", "edit.move_line_down"),
    # Folding
    ("Ctrl+Shift+[", "edit.fold"),
    ("Ctrl+Shift+]", "edit.unfold"),
    # Find / Replace
    ("Ctrl+F", "find.find"),
    ("Ctrl+H", "find.replace"),
    ("Ctrl+Shift+F", "find.find_in_files"),
    # Navigation
    ("Ctrl+G", "navigate.goto_line"),
    ("Ctrl+P", "navigate.goto_file"),
    ("Ctrl+Shift+P", "navigate.command_palette"),
    ("F12", "navigate.goto_definition"),
    ("Shift+F12", "navigate.find_references"),
    ("Ctrl+Shift+O", "navigate.goto_symbol"),
    # Bookmarks
    ("Ctrl+F2", "navigate.toggle_bookmark"),
    ("F2", "navigate.next_bookmark"),
    ("Shift+F2", "navigate.prev_bookmark"),
    # History
    ("Alt+Left", "navigate.history_back"),
    ("Alt+Right", "navigate.history_forward"),
    # View
    ("Ctrl+B", "view.toggle_sidebar"),
    ("Ctrl+J", "view.toggle_bottom_panel"),
    ("Ctrl+`", "view.toggle_terminal"),
    # Run / Debug
    ("F5", "run.run"),
    ("Ctrl+F5", "run.run_no_debug"),
    ("F9", "debug.toggle_breakpoint"),
    ("F10", "debug.step_over"),
    ("F11", "debug.step_into"),
    ("Shift+F11", "debug.step_out"),
    ("Shift+F5", "debug.stop"),
    ("Ctrl+Shift+F5", "debug.restart"),
    # Editor
    ("Ctrl+Shift+L", "edit.format_document"),
    # Zoom
    ("Ctrl+=", "view.zoom_in"),
    ("Ctrl+-", "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)