Repository navigation
fix(config): merge keybindings by name and key instead of name alone - #18870
kronberger-droid merged 5 commits into
Conversation
|
Hey, just a bot checking in! You edited files related to the configuration. |
…e needs `KeyIdentity` is what makes two bindings the same key: modifier, keycode and the mode set, lowered and order-normalised, so `emacs` == `[emacs]` and `[emacs vi_insert]` == `[vi_insert emacs]`. `name_of` lifts the `Option<Value>` name into a comparable `Option<String>`. Both replace raw `Value` equality, which missed every alternative spelling. `ConfigWarning::SharedKeybindingName` reports bindings sharing a name; hashed by the name list so a new duplicate still warns after an earlier one was reported once.
fe55662 to
6df589d
Compare
…siblings Since 0.115 a named binding replaced any earlier binding with the same name, key ignored; atuin's generated config names both its ctrl-r and up-arrow bindings `atuin`, so ctrl-r silently fell back to the built-in history menu (nushell#18848). The merge now takes the name as the primary key and the key identity (modifier, keycode and the mode set, normalised so `emacs` == `[emacs]`) to decide between bindings sharing one. Per incoming binding: an exact name-and-key match is replaced (idempotent re-source, event updates); a named binding with a new key re-keys the unclaimed entry of that name in place, keeping its list position, which is what `$env.config.keybindings.0.keycode = ...` depends on; anything else is appended, with a one-time warning when that fans a name out to a second key. The claimed flag is what lets atuin's two same-named bindings coexist: the first claims its entry exactly, the second starts a new one instead of re-keying its sibling. Assigning `= []` resets the list, which the merge semantics had silently made impossible. Fixes nushell#18848
6df589d to
30ee275
Compare
|
Looks good to me. Let's see what copilot thinks. |
There was a problem hiding this comment.
Pull request overview
Updates keybinding merging to preserve same-named bindings on distinct keys while supporting replacement, re-keying, warnings, and list reset.
Changes:
- Adds normalized key identities and revised merge semantics.
- Adds shared-name warnings and regression tests.
- Documents keybinding merging and reset behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
crates/nu-protocol/src/errors/config.rs |
Adds the shared-name warning. |
crates/nu-protocol/src/config/reedline.rs |
Defines normalized key identities and tests. |
crates/nu-protocol/src/config/mod.rs |
Implements merging, resetting, and regression tests. |
crates/nu-config/default_files/doc_config.nu |
Documents the new behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
ouch haha... i will fix them soon. |
|
no worries at all. sometimes copilot gets things right, sometimes not so much. |
|
Yeah I will just think them over and just add tests along the way. |
… reads it `add_parsed_keybinding` treats the modifier as an unordered `_`-joined set and reads `esc` and `escape` as the same key; `KeyIdentity` compared the lowered source strings, so `control_shift` vs `shift_control` or `esc` vs `escape` counted as different keys and a re-key appended and warned instead of replacing. Modifiers become a component set, `esc` folds to `escape`. Mode names keep their underscores (`vi_normal` is one mode, not `vi` + `normal`), pinned by a test. The exotic overlaps (`space` vs `char_ `, `char_u<hex>`) stay uncanonicalized on purpose: a mismatch only costs an append plus a warning, never a lost binding.
…content `ShellWarning::InvalidConfig` reports as `FirstUse` but hashed to `()`, so every config-warning batch collided in the `ReportLog`: after the first batch of a session, all later config warnings were suppressed regardless of content, and `ConfigWarning`'s manual `Hash` never ran. Delegate to the contained warnings. Dedup is per batch, so a batch that grows re-shows its earlier warnings alongside the new one.
The label gains its missing verb; the help says the bindings remain in the configuration rather than promising they all stay active, since overlapping mode sets still resolve last-write-wins in reedline; the doc no longer implies an emptied list gets the defaults back on the next assignment.
b3fd330 to
c015ab3
Compare
|
done from my side |
|
ok, land it when you're ready |
…19418) ## Description Since #18761 assigning `$env.config.keybindings` or `$env.config.menus` merges into the current list in the config layer. That made the two lists behave unlike every other list in nushell: `=` could not drop a single binding, `menus = []` cleared nothing, and a binding with a bad keycode errored on every prompt until the whole list was cleared. #18828 and #18870 patched the merge (unnamed bindings, then name plus key, with a warning for atuin's shared names in #18848), but each patch added a rule on top of the merge. This PR takes the merge out. Both lists are stored as written, like any other list: ```nu $env.config.keybindings = [...] # replaces the list $env.config.keybindings ++= [...] # appends to it $env.config.keybindings | where name != x # filters it $env.config.keybindings | reverse | uniq-by modifier keycode mode | reverse # drops exact repeats ``` Overlaps are resolved where the list is used, by reedline, with one rule for both lists: entries are applied in order and the last one wins. | | spot | free spot | taken spot | |---|---|---|---| | keybinding | mode, modifier, keycode | filled | replaced | | menu | name | appended | replaced in place | Keys already worked like this in reedline, since `add_binding` is a `HashMap::insert`. Menus did not, since the lookup by name takes the first match, so nushell/reedline#1294 made a later menu replace one of the same name. A keybinding's `name` is only a label and plays no part in what a key does. `SharedKeybindingName` goes, since one name on several keys (atuin) is no longer ambiguous once nothing merges by name. The `KeyIdentity` machinery that mirrored reedline's key parsing goes with it. For keybindings there is a test where nushell hands the list over: `create_keybindings` is checked for last-wins, for `event: null` removing a reedline base binding, and for a later entry covering fewer modes. Menus rely on the reedline test for the same rule, since nushell only passes the list on. ## User-facing changes (Release notes) ### Assigning `$env.config.keybindings` and `$env.config.menus` replaces the list Breaking: `$env.config.keybindings = [...]` and `$env.config.menus = [...]` now replace the whole list, including nushell's default menus and the keys that open them (Tab and Shift+Tab completion, Ctrl+Space, F1 help, Ctrl+X and Ctrl+Z paging, the Ctrl+R history menu). If your config assigns either list, or sets `keybindings` or `menus` inside a `$env.config = {...}` record, switch to `++=` or Tab stops completing. Reedline's own bindings (movement, editing) are not part of the list and stay. ```nu $env.config.keybindings ++= [{ name: my_binding, modifier: control, keycode: char_t, mode: emacs, event: { send: clearscreen } }] ``` To get the defaults back in a running shell, assign them again from a clean `nu -n`: ```nu $env.config.keybindings = (^$nu.current-exe -n -c '$env.config.keybindings | to nuon' | from nuon) $env.config.menus = (^$nu.current-exe -n -c '$env.config.menus | to nuon' | from nuon) ``` Filtering a list now removes what it drops, and `= []` clears either list. When several keybindings bind the same key in the same mode, or several menus share a name, the last one wins. A keybinding's `name` is only a label, so sharing one between keys no longer warns. To unbind a key that reedline itself binds, add an entry for it with `event: null`. ## Additional notes Menus need nushell/reedline#1294, which is in the reedline bump commit before the menus commit. The book still describes the merge in `line_editor.md` (the keybindings section and the menus note), so that needs a follow-up PR to nushell.github.io. Related: #18761, #18828, #18870, #18848.
Description
Since 0.115.0 assigning
$env.config.keybindingsmerges by matching named bindings onnamealone, so a named binding silently replaces an earlier one that binds a different key.Atuin's generated
init.nunames both its ctrl-r and up-arrow bindingsatuin, thus ctrl-r silently fell back to the built-in history menu (#18848).The merge now takes the name as the primary key, with the key identity (
modifier/keycode/mode, normalised soemacs==[emacs]) deciding between bindings that share one.An exact name-and-key match is replaced, so re-sourcing is idempotent and event updates land; a named binding with a new key re-keys the entry of that name in place, keeping its position (
$env.config.keybindings.0.keycode = ...depends on this); anything else appends, with a one-time warning (nu::shell::shared_keybindings_name) when that fans a name out to a second key.A claim flag lets atuin's two same-named bindings coexist: the first claims its entry exactly, so the second appends instead of re-keying its sibling.
Assigning
= []now resets the list, which the merge semantics had silently made impossible.User-facing changes (Release notes)
Fix
$env.config.keybindingsmerging for shared namesFixed an issue where two keybindings sharing a name on different keys silently dropped one of them (broke atuin's ctrl-r).
Nushell now warns once when keybindings share a name, matches mode spellings like
emacsand[emacs]when merging, and$env.config.keybindings = []clears the list again.Additional notes
fixes #18848