Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions packages/backend/app/services/keyboard_shortcuts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""Keyboard-first navigation & shortcuts registry (issue #106)."""

SHORTCUTS = {
"global": [
{"key": "g e", "action": "navigate_expenses", "description": "Go to Expenses"},
{"key": "g b", "action": "navigate_budget", "description": "Go to Budget"},
{"key": "g d", "action": "navigate_dashboard", "description": "Go to Dashboard"},
{"key": "g r", "action": "navigate_reports", "description": "Go to Reports"},
{"key": "g s", "action": "navigate_settings", "description": "Go to Settings"},
{"key": "?", "action": "show_shortcuts", "description": "Show keyboard shortcuts"},
{"key": "/", "action": "focus_search", "description": "Focus search"},
],
"expenses": [
{"key": "n", "action": "new_expense", "description": "New expense"},
{"key": "e", "action": "edit_selected", "description": "Edit selected"},
{"key": "d", "action": "delete_selected", "description": "Delete selected"},
{"key": "f", "action": "filter", "description": "Open filters"},
{"key": "x", "action": "export", "description": "Export expenses"},
{"key": "j", "action": "select_next", "description": "Select next row"},
{"key": "k", "action": "select_prev", "description": "Select previous row"},
{"key": "Enter", "action": "open_selected", "description": "Open selected"},
{"key": "Escape", "action": "clear_selection", "description": "Clear selection"},
],
"forms": [
{"key": "Ctrl+Enter", "action": "submit_form", "description": "Submit form"},
{"key": "Escape", "action": "cancel_form", "description": "Cancel / close"},
{"key": "Tab", "action": "next_field", "description": "Next field"},
{"key": "Shift+Tab", "action": "prev_field", "description": "Previous field"},
],
"dashboard": [
{"key": "r", "action": "refresh", "description": "Refresh data"},
{"key": "1-9", "action": "focus_widget", "description": "Focus widget 1-9"},
{"key": "f", "action": "fullscreen_widget", "description": "Fullscreen current widget"},
],
}


def get_shortcuts(context: str = None) -> dict:
if context and context in SHORTCUTS:
return {"context": context, "shortcuts": SHORTCUTS[context]}
return {"contexts": list(SHORTCUTS.keys()), "all": SHORTCUTS}


def find_shortcut(key: str) -> list:
matches = []
for context, shortcuts in SHORTCUTS.items():
for s in shortcuts:
if s["key"].lower() == key.lower():
matches.append({**s, "context": context})
return matches
19 changes: 19 additions & 0 deletions packages/backend/tests/test_keyboard_shortcuts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from app.services.keyboard_shortcuts import get_shortcuts, find_shortcut

def test_get_all_shortcuts():
r = get_shortcuts()
assert "contexts" in r and "all" in r
assert "global" in r["contexts"]

def test_get_context_shortcuts():
r = get_shortcuts("expenses")
assert r["context"] == "expenses"
assert any(s["action"] == "new_expense" for s in r["shortcuts"])

def test_find_shortcut():
matches = find_shortcut("n")
assert any(m["action"] == "new_expense" for m in matches)

def test_unknown_context():
r = get_shortcuts("nonexistent")
assert "contexts" in r