Fix bindings_for_action
handling of shadowed key bindings (#32220)
Fixes two things: * ~3 months ago [in PR #26420](https://github.com/zed-industries/zed/pull/26420/files#diff-33b58aa2da03d791c2c4761af6012851b7400e348922d64babe5fd48ac2a8e60) `bindings_for_action` was changed to return bindings even when they are shadowed (when the keystrokes would actually do something else). * For edit prediction keybindings there was some odd behavior where bindings for `edit_prediction_conflict` were taking precedence over bindings for `edit_prediction` even when the `edit_prediction_conflict` predicate didn't match. The workaround for this was #24812. The way it worked was: - List all bindings for the action - For each binding, get the highest precedence binding with the same input sequence - If the highest precedence binding has the same action, include this binding. This was the bug - this meant that if a binding in the keymap has the same keystrokes and action it can incorrectly take display precedence even if its context predicate does not pass. - Fix is to check that the highest precedence binding is a full match. To do this efficiently, it's based on an index within the keymap bindings. Also adds `highest_precedence_binding_*` variants which avoid the inefficiency of building lists of bindings just to use the last. Release Notes: - Fixed display of keybindings to skip bindings that are shadowed by a binding that uses the same keystrokes. - Fixed display of `editor::AcceptEditPrediction` bindings to use the normal precedence that prioritizes user bindings.
This commit is contained in:
parent
37fa42d5cc
commit
d801b7b12e
6 changed files with 168 additions and 89 deletions
|
@ -2261,24 +2261,13 @@ impl Editor {
|
|||
window.bindings_for_action_in_context(&AcceptEditPrediction, key_context)
|
||||
};
|
||||
|
||||
AcceptEditPredictionBinding(
|
||||
bindings
|
||||
.into_iter()
|
||||
.filter(|binding| {
|
||||
!in_conflict
|
||||
|| binding
|
||||
.keystrokes()
|
||||
.first()
|
||||
.map_or(false, |keystroke| keystroke.modifiers.modified())
|
||||
})
|
||||
.rev()
|
||||
.min_by_key(|binding| {
|
||||
binding
|
||||
.keystrokes()
|
||||
.first()
|
||||
.map_or(u8::MAX, |k| k.modifiers.number_of_modifiers())
|
||||
}),
|
||||
)
|
||||
AcceptEditPredictionBinding(bindings.into_iter().rev().find(|binding| {
|
||||
!in_conflict
|
||||
|| binding
|
||||
.keystrokes()
|
||||
.first()
|
||||
.map_or(false, |keystroke| keystroke.modifiers.modified())
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn new_file(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue