Skip to content

Commit 97d70c4

Browse files
authored
Merge pull request #234 from Maxteabag/feat/keybinding-editor
feat(keybindings): in-app keybinding editor (leader+k)
2 parents f2c8194 + 94a651b commit 97d70c4

23 files changed

Lines changed: 1232 additions & 81 deletions

‎sqlit/core/keymap.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ def _build_leader_commands(self) -> list[LeaderCommandDef]:
204204
"Actions",
205205
),
206206
LeaderCommandDef("h", "show_help", "Help", "Actions"),
207+
LeaderCommandDef("k", "show_keybinding_editor", "Edit Keybindings", "Actions"),
207208
LeaderCommandDef("space", "telescope", "Telescope", "Actions"),
208209
LeaderCommandDef("slash", "telescope_filter", "Telescope Search", "Actions"),
209210
# Delete menu (vim-style)

‎sqlit/core/state_base.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@ class State(ABC):
9797
"""Base class for hierarchical states."""
9898

9999
help_category: str | None = None
100+
# Name this state uses in keymap defaults / user config (e.g. the
101+
# ``context`` field of :class:`~sqlit.core.keymap.ActionKeyDef`). Used
102+
# by the keymap-manager's conflict detector to derive ancestor chains
103+
# from this state's :attr:`parent` link — so binding the same key in
104+
# a descendant context to a *different* action than an ancestor's
105+
# binding is caught before it lands on disk. ``None`` means the
106+
# state has no corresponding keymap context (intermediate/composite
107+
# states like ``QueryFocusedState`` and the modal-only screens).
108+
keymap_context: str | None = None
100109

101110
def __init__(self, parent: State | None = None):
102111
self.parent = parent

‎sqlit/domains/explorer/state/tree_filter_active.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class TreeFilterActiveState(BlockingState):
1010
"""State when tree filter is active."""
1111

1212
help_category = "Explorer"
13+
keymap_context = "tree_filter"
1314

1415
def _setup_actions(self) -> None:
1516
self.allows("tree_filter_close", help="Close filter")

‎sqlit/domains/explorer/state/tree_focused.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class TreeFocusedState(State):
1010
"""Base state when tree has focus."""
1111

1212
help_category = "Explorer"
13+
keymap_context = "tree"
1314

1415
def _setup_actions(self) -> None:
1516
self.allows("new_connection", label="New", help="New connection")

‎sqlit/domains/explorer/state/tree_visual_mode.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class TreeVisualModeState(State):
1010
"""Tree focused in visual selection mode (vim-style range selection)."""
1111

1212
help_category = "Explorer"
13+
keymap_context = "tree_visual"
1314

1415
def _setup_actions(self) -> None:
1516
self.allows(

‎sqlit/domains/query/state/autocomplete_active.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class AutocompleteActiveState(State):
1111
"""Query editor with autocomplete dropdown visible."""
1212

1313
help_category = "Query Editor (Insert)"
14+
keymap_context = "autocomplete"
1415

1516
def _setup_actions(self) -> None:
1617
self.allows("autocomplete_next", help="Next suggestion", help_key="^j")

‎sqlit/domains/query/state/query_insert.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class QueryInsertModeState(State):
1111
"""Query editor in INSERT mode."""
1212

1313
help_category = "Query Editor (Insert)"
14+
keymap_context = "query_insert"
1415

1516
def _setup_actions(self) -> None:
1617
self.allows("exit_insert_mode", label="Normal Mode", help="Exit to NORMAL mode")

‎sqlit/domains/query/state/query_normal.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class QueryNormalModeState(State):
1111
"""Query editor in NORMAL mode."""
1212

1313
help_category = "Query Editor (Normal)"
14+
keymap_context = "query_normal"
1415

1516
def _setup_actions(self) -> None:
1617
self.allows("enter_insert_mode", label="Insert Mode", help="Enter INSERT mode")

‎sqlit/domains/query/state/query_visual.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class QueryVisualModeState(State):
1111
"""Query editor in VISUAL mode (v)."""
1212

1313
help_category = "Query Editor (Visual)"
14+
keymap_context = "query_visual"
1415

1516
def _setup_actions(self) -> None:
1617
self.allows(

‎sqlit/domains/query/state/query_visual_line.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class QueryVisualLineModeState(State):
1111
"""Query editor in VISUAL LINE mode (V)."""
1212

1313
help_category = "Query Editor (Visual Line)"
14+
keymap_context = "query_visual_line"
1415

1516
def _setup_actions(self) -> None:
1617
self.allows(

0 commit comments

Comments
 (0)