Fix bug with action keybindings not being resolved

This commit is contained in:
Mikayla Maki 2023-03-08 18:11:11 -08:00
parent 152755b043
commit cf6ea6d698
6 changed files with 44 additions and 12 deletions

View file

@ -485,7 +485,7 @@ fn test_navigation_history(cx: &mut gpui::MutableAppContext) {
cx.set_global(DragAndDrop::<Workspace>::default()); cx.set_global(DragAndDrop::<Workspace>::default());
use workspace::item::Item; use workspace::item::Item;
let (_, pane) = cx.add_window(Default::default(), |cx| { let (_, pane) = cx.add_window(Default::default(), |cx| {
Pane::new(None, || unimplemented!(), cx) Pane::new(0, None, || unimplemented!(), cx)
}); });
let buffer = MultiBuffer::build_simple(&sample_text(300, 5, 'a'), cx); let buffer = MultiBuffer::build_simple(&sample_text(300, 5, 'a'), cx);
@ -5564,7 +5564,7 @@ async fn test_following_with_multiple_excerpts(cx: &mut gpui::TestAppContext) {
Settings::test_async(cx); Settings::test_async(cx);
let fs = FakeFs::new(cx.background()); let fs = FakeFs::new(cx.background());
let project = Project::test(fs, ["/file.rs".as_ref()], cx).await; let project = Project::test(fs, ["/file.rs".as_ref()], cx).await;
let (_, pane) = cx.add_window(|cx| Pane::new(None, || unimplemented!(), cx)); let (_, pane) = cx.add_window(|cx| Pane::new(0, None, || unimplemented!(), cx));
let leader = pane.update(cx, |_, cx| { let leader = pane.update(cx, |_, cx| {
let multibuffer = cx.add_model(|_| MultiBuffer::new(0)); let multibuffer = cx.add_model(|_| MultiBuffer::new(0));

View file

@ -97,6 +97,24 @@ pub fn keystroke_label<V: View>(
) -> Container { ) -> Container {
// FIXME: Put the theme in it's own global so we can // FIXME: Put the theme in it's own global so we can
// query the keystroke style on our own // query the keystroke style on our own
keystroke_label_for(
cx.window_id(),
cx.handle().id(),
label_text,
label_style,
keystroke_style,
action,
)
}
pub fn keystroke_label_for(
window_id: usize,
view_id: usize,
label_text: &'static str,
label_style: &ContainedText,
keystroke_style: &ContainedText,
action: Box<dyn Action>,
) -> Container {
Flex::row() Flex::row()
.with_child( .with_child(
Label::new(label_text, label_style.text.clone()) Label::new(label_text, label_style.text.clone())
@ -105,8 +123,8 @@ pub fn keystroke_label<V: View>(
) )
.with_child({ .with_child({
KeystrokeLabel::new( KeystrokeLabel::new(
cx.window_id(), window_id,
cx.handle().id(), view_id,
action, action,
keystroke_style.container, keystroke_style.container,
keystroke_style.text.clone(), keystroke_style.text.clone(),

View file

@ -187,7 +187,14 @@ impl Dock {
) -> Self { ) -> Self {
let position = DockPosition::Hidden(cx.global::<Settings>().default_dock_anchor); let position = DockPosition::Hidden(cx.global::<Settings>().default_dock_anchor);
let pane = cx.add_view(|cx| Pane::new(Some(position.anchor()), background_actions, cx)); let pane = cx.add_view(|cx| {
Pane::new(
cx.handle().id(),
Some(position.anchor()),
background_actions,
cx,
)
});
pane.update(cx, |pane, cx| { pane.update(cx, |pane, cx| {
pane.set_active(false, cx); pane.set_active(false, cx);
}); });

View file

@ -218,6 +218,7 @@ pub struct Pane {
tab_bar_context_menu: ViewHandle<ContextMenu>, tab_bar_context_menu: ViewHandle<ContextMenu>,
docked: Option<DockAnchor>, docked: Option<DockAnchor>,
background_actions: BackgroundActions, background_actions: BackgroundActions,
workspace_id: usize,
} }
pub struct ItemNavHistory { pub struct ItemNavHistory {
@ -275,6 +276,7 @@ enum ItemType {
impl Pane { impl Pane {
pub fn new( pub fn new(
workspace_id: usize,
docked: Option<DockAnchor>, docked: Option<DockAnchor>,
background_actions: BackgroundActions, background_actions: BackgroundActions,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
@ -300,6 +302,7 @@ impl Pane {
tab_bar_context_menu: context_menu, tab_bar_context_menu: context_menu,
docked, docked,
background_actions, background_actions,
workspace_id,
} }
} }
@ -1442,6 +1445,7 @@ impl Pane {
.with_children({ .with_children({
enum KeyboardHint {} enum KeyboardHint {}
let keyboard_hint = &theme.keyboard_hint; let keyboard_hint = &theme.keyboard_hint;
let workspace_id = self.workspace_id;
(self.background_actions)().into_iter().enumerate().map( (self.background_actions)().into_iter().enumerate().map(
move |(idx, (text, action))| { move |(idx, (text, action))| {
let hint_action = action.boxed_clone(); let hint_action = action.boxed_clone();
@ -1449,14 +1453,15 @@ impl Pane {
idx, idx,
cx, cx,
move |state, cx| { move |state, cx| {
theme::ui::keystroke_label( theme::ui::keystroke_label_for(
cx.window_id(),
workspace_id,
text, text,
&keyboard_hint.style_for(state, false), &keyboard_hint.style_for(state, false),
&keystroke_style &keystroke_style
.style_for(state, false) .style_for(state, false)
.keystroke, .keystroke,
hint_action, hint_action,
cx,
) )
.boxed() .boxed()
}, },

View file

@ -606,7 +606,9 @@ impl Workspace {
}) })
.detach(); .detach();
let center_pane = cx.add_view(|cx| Pane::new(None, background_actions, cx)); let workspace_view_id = cx.handle().id();
let center_pane =
cx.add_view(|cx| Pane::new(workspace_view_id, None, background_actions, cx));
let pane_id = center_pane.id(); let pane_id = center_pane.id();
cx.subscribe(&center_pane, move |this, _, event, cx| { cx.subscribe(&center_pane, move |this, _, event, cx| {
this.handle_pane_event(pane_id, event, cx) this.handle_pane_event(pane_id, event, cx)
@ -1438,7 +1440,7 @@ impl Workspace {
} }
fn add_pane(&mut self, cx: &mut ViewContext<Self>) -> ViewHandle<Pane> { fn add_pane(&mut self, cx: &mut ViewContext<Self>) -> ViewHandle<Pane> {
let pane = cx.add_view(|cx| Pane::new(None, self.background_actions, cx)); let pane = cx.add_view(|cx| Pane::new(cx.handle().id(), None, self.background_actions, cx));
let pane_id = pane.id(); let pane_id = pane.id();
cx.subscribe(&pane, move |this, _, event, cx| { cx.subscribe(&pane, move |this, _, event, cx| {
this.handle_pane_event(pane_id, event, cx) this.handle_pane_event(pane_id, event, cx)

View file

@ -46,8 +46,8 @@ export default function workspace(colorScheme: ColorScheme) {
color: background(layer, "on"), color: background(layer, "on"),
icon: "icons/logo_96.svg", icon: "icons/logo_96.svg",
dimensions: { dimensions: {
width: 240, width: 256,
height: 240, height: 256,
} }
}, },
keyboardHints: { keyboardHints: {
@ -67,7 +67,7 @@ export default function workspace(colorScheme: ColorScheme) {
...text(colorScheme.lowest, "sans", "hovered", { size: "sm" }), ...text(colorScheme.lowest, "sans", "hovered", { size: "sm" }),
} }
}, },
keyboardHintWidth: 240, keyboardHintWidth: 256,
}, },
joiningProjectAvatar: { joiningProjectAvatar: {
cornerRadius: 40, cornerRadius: 40,