diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index c225cabd9b..a98a998c5f 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -4016,7 +4016,7 @@ impl Editor { anchor: Anchor, window: &mut Window, cx: &mut Context, - ) -> Entity { + ) -> Entity { 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)> = + 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(); + }, + ) }) }