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());
use workspace::item::Item;
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);
@ -5564,7 +5564,7 @@ async fn test_following_with_multiple_excerpts(cx: &mut gpui::TestAppContext) {
Settings::test_async(cx);
let fs = FakeFs::new(cx.background());
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 multibuffer = cx.add_model(|_| MultiBuffer::new(0));

View file

@ -97,6 +97,24 @@ pub fn keystroke_label<V: View>(
) -> Container {
// FIXME: Put the theme in it's own global so we can
// 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()
.with_child(
Label::new(label_text, label_style.text.clone())
@ -105,8 +123,8 @@ pub fn keystroke_label<V: View>(
)
.with_child({
KeystrokeLabel::new(
cx.window_id(),
cx.handle().id(),
window_id,
view_id,
action,
keystroke_style.container,
keystroke_style.text.clone(),

View file

@ -187,7 +187,14 @@ impl Dock {
) -> Self {
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.set_active(false, cx);
});

View file

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

View file

@ -606,7 +606,9 @@ impl Workspace {
})
.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();
cx.subscribe(&center_pane, move |this, _, 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> {
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();
cx.subscribe(&pane, move |this, _, 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"),
icon: "icons/logo_96.svg",
dimensions: {
width: 240,
height: 240,
width: 256,
height: 256,
}
},
keyboardHints: {
@ -67,7 +67,7 @@ export default function workspace(colorScheme: ColorScheme) {
...text(colorScheme.lowest, "sans", "hovered", { size: "sm" }),
}
},
keyboardHintWidth: 240,
keyboardHintWidth: 256,
},
joiningProjectAvatar: {
cornerRadius: 40,