Skip to content

feat: load keybindings from config file (#5 phase 2) - #31

Merged
m5d215 merged 1 commit into
mainfrom
feat/keymap-config
May 13, 2026
Merged

m5d215 merged 1 commit into
mainfrom
feat/keymap-config

Conversation

@m5d215

@m5d215 m5d215 commented May 13, 2026

Copy link
Copy Markdown
Owner

Phase 2 of #5. Builds on #30 (action-map refactor): the TUI now reads an optional config file and merges user bindings onto the built-in defaults.

Closes #5.

Summary

  • Config path: \$XDG_CONFIG_HOME/markdown-browser/config.toml (default ~/.config/markdown-browser/config.toml). Missing file is silent.
  • TOML schema: per-mode tables under [keys.normal] / [keys.yank] / [keys.toc] / [keys.help] / [keys.dir]. Each row is \"<chord>\" = \"<action_name>\".
  • Action names are the snake_case form of the Action enum (cursor_down, history_back, dir_go_up, ...). A test enforces the name table is complete so every shipped default round-trips through from_name.
  • Chord parser accepts ctrl+ / alt+ / shift+ prefixes (any order, case-insensitive), single characters case-sensitive, and named keys / f1–f12 case-insensitive. shift+tab collapses to BackTab and shift+<lower> to the uppercase char before the existing SHIFT normalization step runs.
  • Errors are non-fatal — unknown modes, bad chord syntax, and unknown action names accumulate as LoadedKeymaps::warnings. The TUI surfaces the first one in the status bar at startup with a (+N more) suffix when there are extras; defaults stay intact when a binding fails.
  • Merge semantics: user bindings add to defaults rather than replacing them. After \"shift+h\" = \"history_back\", both H and [ step back through history. Unbinding a default needs a future syntax (\"[\" = \"none\") — left out until requested.
  • README: new "Customizing" subsection with a worked example plus chord syntax reference.

Deps added: serde (derive) and toml (parse + serde features, no rest of the surface area).

Example

```toml

~/.config/markdown-browser/config.toml

[keys.normal]
"shift+h" = "history_back"
"shift+l" = "history_forward"
"ctrl+e" = "toggle_shortcodes"

[keys.dir]
"backspace" = "dir_go_up"
```

Test plan

  • `cargo build --locked` clean
  • `cargo clippy --locked --all-targets -- -D warnings` clean
  • `cargo fmt --check` clean
  • `cargo test --locked` — 6 unit tests covering chord parsing (simple keys, modifiers, named keys, shift normalization, garbage rejection) and the action-name round-trip.
  • Manual TUI: no-config default behavior unchanged. With `"shift+h" = "history_back"` configured, H navigates back while [ still does too (intentional merge). With deliberately broken config, status bar shows the parse warning and the TUI starts with defaults.

🤖 Generated with Claude Code

…phase 2)

Phase 2 of #5. The TUI now reads an optional config file at
`$XDG_CONFIG_HOME/markdown-browser/config.toml` (default
`~/.config/...`) and layers it onto the built-in defaults.

Each `[keys.<mode>]` table maps a chord string to an action name.
Modes: normal / yank / toc / help / dir. Action names are the
snake_case form of the `Action` enum (`cursor_down`, `history_back`,
...). Bindings merge into the defaults rather than replacing them —
no way to unbind a default yet, deferred until the need shows up.

Chord parser accepts `ctrl+` / `alt+` / `shift+` prefixes (any order,
case-insensitive), single characters case-sensitive, named keys
case-insensitive (`esc`, `enter`, `tab`, `backtab`, `space`,
`left`/`right`/`up`/`down`, `home`/`end`, `pageup`/`pagedown`,
`f1`–`f12`). `shift+tab` collapses to `BackTab` and `shift+<lower>`
to the uppercase char before the existing SHIFT normalization runs.

Parse failures are non-fatal: unknown keys, unknown actions, and
unknown modes accumulate as warnings; the first warning surfaces in
the status bar at startup (with a `+N more` suffix when there are
more), TUI starts normally with the defaults left intact.

Adds `serde` + `toml` (parse + serde features only).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@m5d215
m5d215 enabled auto-merge May 13, 2026 06:05
@m5d215
m5d215 merged commit 302c99e into main May 13, 2026
3 checks passed
@m5d215
m5d215 deleted the feat/keymap-config branch May 13, 2026 06:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Customizable keybindings

1 participant