Make toggle dock actions appear in the command palette
This commit is contained in:
parent
8832248bb9
commit
66b3be8687
3 changed files with 74 additions and 20 deletions
|
@ -3390,16 +3390,15 @@ impl<'a, 'b, 'c, V: View> LayoutContext<'a, 'b, 'c, V> {
|
||||||
self.keystroke_matcher
|
self.keystroke_matcher
|
||||||
.bindings_for_action_type(action.as_any().type_id())
|
.bindings_for_action_type(action.as_any().type_id())
|
||||||
.find_map(|b| {
|
.find_map(|b| {
|
||||||
handler_depth
|
let highest_handler = handler_depth?;
|
||||||
.map(|highest_handler| {
|
if action.eq(b.action())
|
||||||
if (0..=highest_handler).any(|depth| b.match_context(&contexts[depth..])) {
|
&& (0..=highest_handler).any(|depth| b.match_context(&contexts[depth..]))
|
||||||
|
{
|
||||||
Some(b.keystrokes().into())
|
Some(b.keystrokes().into())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.flatten()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn notify_if_view_ancestors_change(&mut self, view_id: usize) {
|
fn notify_if_view_ancestors_change(&mut self, view_id: usize) {
|
||||||
|
@ -6090,6 +6089,53 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[crate::test(self)]
|
||||||
|
fn test_keystrokes_for_action_with_data(cx: &mut TestAppContext) {
|
||||||
|
#[derive(Clone, Debug, Deserialize, PartialEq)]
|
||||||
|
struct ActionWithArg {
|
||||||
|
#[serde(default)]
|
||||||
|
arg: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct View;
|
||||||
|
impl super::Entity for View {
|
||||||
|
type Event = ();
|
||||||
|
}
|
||||||
|
impl super::View for View {
|
||||||
|
fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
|
||||||
|
Empty::new().into_any()
|
||||||
|
}
|
||||||
|
fn ui_name() -> &'static str {
|
||||||
|
"View"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl_actions!(test, [ActionWithArg]);
|
||||||
|
|
||||||
|
let (window_id, view) = cx.add_window(|_| View);
|
||||||
|
cx.update(|cx| {
|
||||||
|
cx.add_global_action(|_: &ActionWithArg, _| {});
|
||||||
|
cx.add_bindings(vec![
|
||||||
|
Binding::new("a", ActionWithArg { arg: false }, None),
|
||||||
|
Binding::new("shift-a", ActionWithArg { arg: true }, None),
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
let actions = cx.available_actions(window_id, view.id());
|
||||||
|
assert_eq!(
|
||||||
|
actions[0].1.as_any().downcast_ref::<ActionWithArg>(),
|
||||||
|
Some(&ActionWithArg { arg: false })
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
actions[0]
|
||||||
|
.2
|
||||||
|
.iter()
|
||||||
|
.map(|b| b.keystrokes()[0].clone())
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
|
vec![Keystroke::parse("a").unwrap()],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[crate::test(self)]
|
#[crate::test(self)]
|
||||||
async fn test_model_condition(cx: &mut TestAppContext) {
|
async fn test_model_condition(cx: &mut TestAppContext) {
|
||||||
struct Counter(usize);
|
struct Counter(usize);
|
||||||
|
|
|
@ -394,17 +394,18 @@ impl<'a> WindowContext<'a> {
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(move |(name, (type_id, deserialize))| {
|
.filter_map(move |(name, (type_id, deserialize))| {
|
||||||
if let Some(action_depth) = handler_depths_by_action_type.get(type_id).copied() {
|
if let Some(action_depth) = handler_depths_by_action_type.get(type_id).copied() {
|
||||||
Some((
|
let action = deserialize("{}").ok()?;
|
||||||
*name,
|
let bindings = self
|
||||||
deserialize("{}").ok()?,
|
.keystroke_matcher
|
||||||
self.keystroke_matcher
|
|
||||||
.bindings_for_action_type(*type_id)
|
.bindings_for_action_type(*type_id)
|
||||||
.filter(|b| {
|
.filter(|b| {
|
||||||
(0..=action_depth).any(|depth| b.match_context(&contexts[depth..]))
|
action.eq(b.action())
|
||||||
|
&& (0..=action_depth)
|
||||||
|
.any(|depth| b.match_context(&contexts[depth..]))
|
||||||
})
|
})
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect(),
|
.collect();
|
||||||
))
|
Some((*name, action, bindings))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,16 +105,19 @@ pub struct RemoveWorktreeFromProject(pub WorktreeId);
|
||||||
|
|
||||||
#[derive(Copy, Clone, Default, Deserialize, PartialEq)]
|
#[derive(Copy, Clone, Default, Deserialize, PartialEq)]
|
||||||
pub struct ToggleLeftDock {
|
pub struct ToggleLeftDock {
|
||||||
|
#[serde(default = "default_true")]
|
||||||
pub focus: bool,
|
pub focus: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Default, Deserialize, PartialEq)]
|
#[derive(Copy, Clone, Default, Deserialize, PartialEq)]
|
||||||
pub struct ToggleBottomDock {
|
pub struct ToggleBottomDock {
|
||||||
|
#[serde(default = "default_true")]
|
||||||
pub focus: bool,
|
pub focus: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Default, Deserialize, PartialEq)]
|
#[derive(Copy, Clone, Default, Deserialize, PartialEq)]
|
||||||
pub struct ToggleRightDock {
|
pub struct ToggleRightDock {
|
||||||
|
#[serde(default = "default_true")]
|
||||||
pub focus: bool,
|
pub focus: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3378,6 +3381,10 @@ fn parse_pixel_position_env_var(value: &str) -> Option<Vector2F> {
|
||||||
Some(vec2f(width as f32, height as f32))
|
Some(vec2f(width as f32, height as f32))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn default_true() -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue