Make sure we display keybindings on gutter menu (#58856)
Closes https://github.com/zed-industries/zed/issues/58820 Some menu items there don't have have a bindable action and/or a default keybinding, so they won't show anything by default. Right now, only "Set Breakpoint" and "Set Log Breakpoint" will show something right off the bat. Release Notes: - N/A
This commit is contained in:
1 parent
ef731e7769
commit
bf5702c2fa
1 file changed
+86
-61
+86
-61
@@ -4016,7 +4016,7 @@ impl Editor {
|
||||
anchor: Anchor,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Entity<ui::ContextMenu> {
|
||||
) -> Entity<ContextMenu> {
|
||||
let weak_editor = cx.weak_entity();
|
||||
let focus_handle = self.focus_handle(cx);
|
||||
|
||||
@@ -4071,37 +4071,50 @@ impl Editor {
|
||||
|
||||
let run_to_cursor = window.is_action_available(&RunToCursor, cx);
|
||||
|
||||
let toggle_state_msg = breakpoint.as_ref().map_or(None, |bp| match bp.1.state {
|
||||
BreakpointState::Enabled => Some("Disable"),
|
||||
BreakpointState::Disabled => Some("Enable"),
|
||||
});
|
||||
let toggle_state_entry: Option<(&str, Box<dyn Action>)> =
|
||||
breakpoint.as_ref().map(|bp| match bp.1.state {
|
||||
BreakpointState::Enabled => {
|
||||
("Disable", crate::actions::DisableBreakpoint.boxed_clone())
|
||||
}
|
||||
BreakpointState::Disabled => {
|
||||
("Enable", crate::actions::EnableBreakpoint.boxed_clone())
|
||||
}
|
||||
});
|
||||
|
||||
let (anchor, breakpoint) =
|
||||
breakpoint.unwrap_or_else(|| (anchor, Arc::new(Breakpoint::new_standard())));
|
||||
|
||||
ui::ContextMenu::build(window, cx, |menu, _, _cx| {
|
||||
ContextMenu::build(window, cx, |menu, _, _cx| {
|
||||
menu.on_blur_subscription(Subscription::new(|| {}))
|
||||
.context(focus_handle)
|
||||
.when(run_to_cursor, |this| {
|
||||
let weak_editor = weak_editor.clone();
|
||||
this.entry("Run to Cursor", None, move |window, cx| {
|
||||
weak_editor
|
||||
.update(cx, |editor, cx| {
|
||||
editor.change_selections(
|
||||
SelectionEffects::no_scroll(),
|
||||
window,
|
||||
cx,
|
||||
|s| s.select_ranges([Point::new(row, 0)..Point::new(row, 0)]),
|
||||
);
|
||||
})
|
||||
.ok();
|
||||
this.entry(
|
||||
"Run to Cursor",
|
||||
Some(RunToCursor.boxed_clone()),
|
||||
move |window, cx| {
|
||||
weak_editor
|
||||
.update(cx, |editor, cx| {
|
||||
editor.change_selections(
|
||||
SelectionEffects::no_scroll(),
|
||||
window,
|
||||
cx,
|
||||
|s| {
|
||||
s.select_ranges(
|
||||
[Point::new(row, 0)..Point::new(row, 0)],
|
||||
)
|
||||
},
|
||||
);
|
||||
})
|
||||
.ok();
|
||||
|
||||
window.dispatch_action(Box::new(RunToCursor), cx);
|
||||
})
|
||||
window.dispatch_action(Box::new(RunToCursor), cx);
|
||||
},
|
||||
)
|
||||
.separator()
|
||||
})
|
||||
.when_some(toggle_state_msg, |this, msg| {
|
||||
this.entry(msg, None, {
|
||||
.when_some(toggle_state_entry, |this, (msg, action)| {
|
||||
this.entry(msg, Some(action), {
|
||||
let weak_editor = weak_editor.clone();
|
||||
let breakpoint = breakpoint.clone();
|
||||
move |_window, cx| {
|
||||
@@ -4118,39 +4131,47 @@ impl Editor {
|
||||
}
|
||||
})
|
||||
})
|
||||
.entry(set_breakpoint_msg, None, {
|
||||
let weak_editor = weak_editor.clone();
|
||||
let breakpoint = breakpoint.clone();
|
||||
move |_window, cx| {
|
||||
weak_editor
|
||||
.update(cx, |this, cx| {
|
||||
this.edit_breakpoint_at_anchor(
|
||||
anchor,
|
||||
breakpoint.as_ref().clone(),
|
||||
BreakpointEditAction::Toggle,
|
||||
cx,
|
||||
);
|
||||
})
|
||||
.log_err();
|
||||
}
|
||||
})
|
||||
.entry(log_breakpoint_msg, None, {
|
||||
let breakpoint = breakpoint.clone();
|
||||
let weak_editor = weak_editor.clone();
|
||||
move |window, cx| {
|
||||
weak_editor
|
||||
.update(cx, |this, cx| {
|
||||
this.add_edit_breakpoint_block(
|
||||
anchor,
|
||||
breakpoint.as_ref(),
|
||||
BreakpointPromptEditAction::Log,
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
})
|
||||
.log_err();
|
||||
}
|
||||
})
|
||||
.entry(
|
||||
set_breakpoint_msg,
|
||||
Some(crate::actions::ToggleBreakpoint.boxed_clone()),
|
||||
{
|
||||
let weak_editor = weak_editor.clone();
|
||||
let breakpoint = breakpoint.clone();
|
||||
move |_window, cx| {
|
||||
weak_editor
|
||||
.update(cx, |this, cx| {
|
||||
this.edit_breakpoint_at_anchor(
|
||||
anchor,
|
||||
breakpoint.as_ref().clone(),
|
||||
BreakpointEditAction::Toggle,
|
||||
cx,
|
||||
);
|
||||
})
|
||||
.log_err();
|
||||
}
|
||||
},
|
||||
)
|
||||
.entry(
|
||||
log_breakpoint_msg,
|
||||
Some(crate::actions::EditLogBreakpoint.boxed_clone()),
|
||||
{
|
||||
let breakpoint = breakpoint.clone();
|
||||
let weak_editor = weak_editor.clone();
|
||||
move |window, cx| {
|
||||
weak_editor
|
||||
.update(cx, |this, cx| {
|
||||
this.add_edit_breakpoint_block(
|
||||
anchor,
|
||||
breakpoint.as_ref(),
|
||||
BreakpointPromptEditAction::Log,
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
})
|
||||
.log_err();
|
||||
}
|
||||
},
|
||||
)
|
||||
.entry(condition_breakpoint_msg, None, {
|
||||
let breakpoint = breakpoint.clone();
|
||||
let weak_editor = weak_editor.clone();
|
||||
@@ -4186,13 +4207,17 @@ impl Editor {
|
||||
}
|
||||
})
|
||||
.separator()
|
||||
.entry(set_bookmark_msg, None, move |_window, cx| {
|
||||
weak_editor
|
||||
.update(cx, |this, cx| {
|
||||
this.toggle_bookmark_at_anchor(anchor, cx);
|
||||
})
|
||||
.log_err();
|
||||
})
|
||||
.entry(
|
||||
set_bookmark_msg,
|
||||
Some(ToggleBookmark.boxed_clone()),
|
||||
move |_window, cx| {
|
||||
weak_editor
|
||||
.update(cx, |this, cx| {
|
||||
this.toggle_bookmark_at_anchor(anchor, cx);
|
||||
})
|
||||
.log_err();
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user