Revert "Use correct context path for focused element in WindowContext::bindings_for_action (#18843)" (#20367)
@JosephTLyons found that this broke display of keybindings in the recent projects modal. Release Notes: - N/A
This commit is contained in:
parent
453c41205b
commit
2c4984091c
3 changed files with 34 additions and 34 deletions
|
@ -68,7 +68,7 @@ pub(crate) struct DispatchNodeId(usize);
|
||||||
|
|
||||||
pub(crate) struct DispatchTree {
|
pub(crate) struct DispatchTree {
|
||||||
node_stack: Vec<DispatchNodeId>,
|
node_stack: Vec<DispatchNodeId>,
|
||||||
context_stack: Vec<KeyContext>,
|
pub(crate) context_stack: Vec<KeyContext>,
|
||||||
view_stack: Vec<EntityId>,
|
view_stack: Vec<EntityId>,
|
||||||
nodes: Vec<DispatchNode>,
|
nodes: Vec<DispatchNode>,
|
||||||
focusable_node_ids: FxHashMap<FocusId, DispatchNodeId>,
|
focusable_node_ids: FxHashMap<FocusId, DispatchNodeId>,
|
||||||
|
@ -396,13 +396,13 @@ impl DispatchTree {
|
||||||
pub fn bindings_for_action(
|
pub fn bindings_for_action(
|
||||||
&self,
|
&self,
|
||||||
action: &dyn Action,
|
action: &dyn Action,
|
||||||
context_path: &[KeyContext],
|
context_stack: &[KeyContext],
|
||||||
) -> Vec<KeyBinding> {
|
) -> Vec<KeyBinding> {
|
||||||
let keymap = self.keymap.borrow();
|
let keymap = self.keymap.borrow();
|
||||||
keymap
|
keymap
|
||||||
.bindings_for_action(action)
|
.bindings_for_action(action)
|
||||||
.filter(|binding| {
|
.filter(|binding| {
|
||||||
let (bindings, _) = keymap.bindings_for_input(&binding.keystrokes, context_path);
|
let (bindings, _) = keymap.bindings_for_input(&binding.keystrokes, context_stack);
|
||||||
bindings
|
bindings
|
||||||
.iter()
|
.iter()
|
||||||
.next()
|
.next()
|
||||||
|
@ -519,13 +519,6 @@ impl DispatchTree {
|
||||||
dispatch_path
|
dispatch_path
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn context_path(&self, node_id: DispatchNodeId) -> SmallVec<[KeyContext; 32]> {
|
|
||||||
self.dispatch_path(node_id)
|
|
||||||
.into_iter()
|
|
||||||
.filter_map(|node_id| self.node(node_id).context.clone())
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn focus_path(&self, focus_id: FocusId) -> SmallVec<[FocusId; 8]> {
|
pub fn focus_path(&self, focus_id: FocusId) -> SmallVec<[FocusId; 8]> {
|
||||||
let mut focus_path: SmallVec<[FocusId; 8]> = SmallVec::new();
|
let mut focus_path: SmallVec<[FocusId; 8]> = SmallVec::new();
|
||||||
let mut current_node_id = self.focusable_node_ids.get(&focus_id).copied();
|
let mut current_node_id = self.focusable_node_ids.get(&focus_id).copied();
|
||||||
|
|
|
@ -139,7 +139,7 @@ impl Keymap {
|
||||||
pub fn bindings_for_input(
|
pub fn bindings_for_input(
|
||||||
&self,
|
&self,
|
||||||
input: &[Keystroke],
|
input: &[Keystroke],
|
||||||
context_path: &[KeyContext],
|
context_stack: &[KeyContext],
|
||||||
) -> (SmallVec<[KeyBinding; 1]>, bool) {
|
) -> (SmallVec<[KeyBinding; 1]>, bool) {
|
||||||
let possibilities = self.bindings().rev().filter_map(|binding| {
|
let possibilities = self.bindings().rev().filter_map(|binding| {
|
||||||
binding
|
binding
|
||||||
|
@ -151,8 +151,8 @@ impl Keymap {
|
||||||
let mut is_pending = None;
|
let mut is_pending = None;
|
||||||
|
|
||||||
'outer: for (binding, pending) in possibilities {
|
'outer: for (binding, pending) in possibilities {
|
||||||
for depth in (0..=context_path.len()).rev() {
|
for depth in (0..=context_stack.len()).rev() {
|
||||||
if self.binding_enabled(binding, &context_path[0..depth]) {
|
if self.binding_enabled(binding, &context_stack[0..depth]) {
|
||||||
if is_pending.is_none() {
|
if is_pending.is_none() {
|
||||||
is_pending = Some(pending);
|
is_pending = Some(pending);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3683,11 +3683,22 @@ impl<'a> WindowContext<'a> {
|
||||||
|
|
||||||
/// Returns all available actions for the focused element.
|
/// Returns all available actions for the focused element.
|
||||||
pub fn available_actions(&self) -> Vec<Box<dyn Action>> {
|
pub fn available_actions(&self) -> Vec<Box<dyn Action>> {
|
||||||
|
let node_id = self
|
||||||
|
.window
|
||||||
|
.focus
|
||||||
|
.and_then(|focus_id| {
|
||||||
|
self.window
|
||||||
|
.rendered_frame
|
||||||
|
.dispatch_tree
|
||||||
|
.focusable_node_id(focus_id)
|
||||||
|
})
|
||||||
|
.unwrap_or_else(|| self.window.rendered_frame.dispatch_tree.root_node_id());
|
||||||
|
|
||||||
let mut actions = self
|
let mut actions = self
|
||||||
.window
|
.window
|
||||||
.rendered_frame
|
.rendered_frame
|
||||||
.dispatch_tree
|
.dispatch_tree
|
||||||
.available_actions(self.focused_node_id());
|
.available_actions(node_id);
|
||||||
for action_type in self.global_action_listeners.keys() {
|
for action_type in self.global_action_listeners.keys() {
|
||||||
if let Err(ix) = actions.binary_search_by_key(action_type, |a| a.as_any().type_id()) {
|
if let Err(ix) = actions.binary_search_by_key(action_type, |a| a.as_any().type_id()) {
|
||||||
let action = self.actions.build_action_type(action_type).ok();
|
let action = self.actions.build_action_type(action_type).ok();
|
||||||
|
@ -3701,9 +3712,13 @@ impl<'a> WindowContext<'a> {
|
||||||
|
|
||||||
/// Returns key bindings that invoke the given action on the currently focused element.
|
/// Returns key bindings that invoke the given action on the currently focused element.
|
||||||
pub fn bindings_for_action(&self, action: &dyn Action) -> Vec<KeyBinding> {
|
pub fn bindings_for_action(&self, action: &dyn Action) -> Vec<KeyBinding> {
|
||||||
let dispatch_tree = &self.window.rendered_frame.dispatch_tree;
|
self.window
|
||||||
dispatch_tree
|
.rendered_frame
|
||||||
.bindings_for_action(action, &dispatch_tree.context_path(self.focused_node_id()))
|
.dispatch_tree
|
||||||
|
.bindings_for_action(
|
||||||
|
action,
|
||||||
|
&self.window.rendered_frame.dispatch_tree.context_stack,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns key bindings that invoke the given action on the currently focused element.
|
/// Returns key bindings that invoke the given action on the currently focused element.
|
||||||
|
@ -3719,23 +3734,15 @@ impl<'a> WindowContext<'a> {
|
||||||
) -> Vec<KeyBinding> {
|
) -> Vec<KeyBinding> {
|
||||||
let dispatch_tree = &self.window.rendered_frame.dispatch_tree;
|
let dispatch_tree = &self.window.rendered_frame.dispatch_tree;
|
||||||
|
|
||||||
if let Some(node_id) = dispatch_tree.focusable_node_id(focus_handle.id) {
|
let Some(node_id) = dispatch_tree.focusable_node_id(focus_handle.id) else {
|
||||||
dispatch_tree.bindings_for_action(action, &dispatch_tree.context_path(node_id))
|
return vec![];
|
||||||
} else {
|
};
|
||||||
vec![]
|
let context_stack: Vec<_> = dispatch_tree
|
||||||
}
|
.dispatch_path(node_id)
|
||||||
}
|
.into_iter()
|
||||||
|
.filter_map(|node_id| dispatch_tree.node(node_id).context.clone())
|
||||||
fn focused_node_id(&self) -> DispatchNodeId {
|
.collect();
|
||||||
self.window
|
dispatch_tree.bindings_for_action(action, &context_stack)
|
||||||
.focus
|
|
||||||
.and_then(|focus_id| {
|
|
||||||
self.window
|
|
||||||
.rendered_frame
|
|
||||||
.dispatch_tree
|
|
||||||
.focusable_node_id(focus_id)
|
|
||||||
})
|
|
||||||
.unwrap_or_else(|| self.window.rendered_frame.dispatch_tree.root_node_id())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a generic event listener that invokes the given listener with the view and context associated with the given view handle.
|
/// Returns a generic event listener that invokes the given listener with the view and context associated with the given view handle.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue