Skip to content

Visual Studio Code, rebuilt in Rust

Rust

feat(menus): editor/title/run split button in the editor title

rokarturf295a7febb32
diff --git a/native/crates/app/src/menus.rs b/native/crates/app/src/menus.rs
index dea036d2e51..eac7de2d50e 100644
--- a/native/crates/app/src/menus.rs
+++ b/native/crates/app/src/menus.rs
@@ -104,6 +104,8 @@ pub enum MenuId {
/// `MenuId.MultiDiffEditorFileToolbar`: a multi diff editor file header's toolbar.
MultiDiffEditorFileToolbar,
EditorTitle,
+ /// `MenuId.EditorTitleRun`: the editor title's Run or Debug... split button.
+ EditorTitleRun,
/// `MenuId.InteractiveToolbar`: the interactive window's and REPL editor's toolbar.
InteractiveToolbar,
/// `MenuId.NotebookOutputToolbar`: the `...` dropdown left of a notebook output.
@@ -537,6 +539,8 @@ const WORKBENCH_MENUS: &[Row] = &[
(MenuId::EditorTitleContext, Some(MenuId::EditorSplitMoveSubmenu), "", "Split & Move", "5_split", 15., None, None),
(MenuId::EditorTitleContext, None, "workbench.action.moveEditorToNewWindow", "Move into New Window", "7_new_window", 10., None, None),
(MenuId::EditorTitleContext, None, "workbench.action.copyEditorToNewWindow", "Copy into New Window", "7_new_window", 20., None, None),
+ // debug.contribution.ts: Run or Debug..., a split button (`isSplitButton: { togglePrimaryAction: true }`).
+ (MenuId::EditorTitle, Some(MenuId::EditorTitleRun), "", "Run or Debug...", "navigation", -1., None, None),
// editor.contribution.ts: the editor title's `...` (its groups but `navigation`). Lock Group is a title icon in an
// editor window and Maximize Group needs several groups.
(MenuId::EditorTitle, Some(MenuId::DiffEditorViewSubmenu), "", "Diff View", "1_diff", 10., Some("isInDiffEditor && !isSessionsWindow"), None),
@@ -917,7 +921,7 @@ pub fn workbench_menus() -> Vec<MenuItem> {
/// menusExtensionPoint.ts `apiMenus`: the `contributes.menus` keys of the menus the port shows. `commandPalette`
/// is read by `command_palette::menu`.
-const API_MENUS: [(&str, MenuId); 50] = [
+const API_MENUS: [(&str, MenuId); 51] = [
("file/newFile", MenuId::NewFile),
("editor/context", MenuId::EditorContext),
("explorer/context", MenuId::ExplorerContext),
@@ -932,6 +936,7 @@ const API_MENUS: [(&str, MenuId); 50] = [
("diffEditor/gutter/hunk", MenuId::DiffEditorHunkToolbar),
("multiDiffEditor/resource/title", MenuId::MultiDiffEditorFileToolbar),
("editor/title", MenuId::EditorTitle),
+ ("editor/title/run", MenuId::EditorTitleRun),
("interactive/toolbar", MenuId::InteractiveToolbar),
("notebook/toolbar", MenuId::NotebookToolbar),
("notebook/cell/title", MenuId::NotebookCellTitle),
diff --git a/native/crates/app/src/menus/tests.rs b/native/crates/app/src/menus/tests.rs
index 20588331340..8ef9c962552 100644
--- a/native/crates/app/src/menus/tests.rs
+++ b/native/crates/app/src/menus/tests.rs
@@ -191,6 +191,7 @@ fn api_menu_keys_reach_their_menus() {
("scm/historyItemRef/context", MenuId::ScmHistoryItemRefContext),
("viewContainer/title", MenuId::ViewContainerTitle),
("extension/context", MenuId::ExtensionContext),
+ ("editor/title/run", MenuId::EditorTitleRun),
];
for (key, menu) in keys {
let item = json!({ "command": "k.run", "when": "viewContainer == workbench.view.debug" });
diff --git a/native/crates/app/src/workbench/context_menu.rs b/native/crates/app/src/workbench/context_menu.rs
index 231e7d00ead..c784008350d 100644
--- a/native/crates/app/src/workbench/context_menu.rs
+++ b/native/crates/app/src/workbench/context_menu.rs
@@ -62,6 +62,9 @@ pub struct ContextMenu {
mouse_up_enabled: bool,
/// `menuActionOptions.arg` and `getActionsContext`, passed to the command that runs.
pub(super) args: Vec<Value>,
+ /// A split button's dropdown: the workspace storage key that remembers the command run from it
+ /// (`DropdownWithDefaultActionViewItem`'s `onWillRun`).
+ pub(super) primary_action_storage_key: Option<String>,
focus: FocusHandle,
/// None when nothing had focus, as a title bar right-click in a window without editors.
pub(super) focus_to_return: Option<FocusHandle>,
@@ -139,6 +142,7 @@ impl Workbench {
alt: window.modifiers().alt,
mouse_up_enabled: false,
args,
+ primary_action_storage_key: None,
focus,
focus_to_return,
shown: self.context_menus_shown,
@@ -347,6 +351,9 @@ impl Workbench {
_ => id.clone(),
};
let args = menu.args.clone();
+ if let Some(key) = &menu.primary_action_storage_key {
+ self.workspace_storage.lock().unwrap().set(key, id.clone());
+ }
self.hide_context_menu(window, cx);
let outcome = self.execute_command(&id, args, window, cx);
super::keyboard::report_failure(outcome, cx);
diff --git a/native/crates/app/src/workbench/editor_view.rs b/native/crates/app/src/workbench/editor_view.rs
index ec7597f6c3d..153819fe35d 100644
--- a/native/crates/app/src/workbench/editor_view.rs
+++ b/native/crates/app/src/workbench/editor_view.rs
@@ -431,6 +431,11 @@ impl Workbench {
let button = self.submenu_button(*submenu, Some(&crate::menus::CommandIcon::Codicon("gear".into())), item.title.clone(), context.clone(), Vec::new(), foreground, cx);
actions.push((item.order, self.title_action(bar, &actions.len().to_string(), button, cx)));
}
+ crate::menus::Entry::Submenu { submenu: submenu @ crate::menus::MenuId::EditorTitleRun, .. } => {
+ if let Some(button) = self.split_button(*submenu, item.title.clone(), &context, resource.clone(), foreground, cx) {
+ actions.push((item.order, self.title_action(bar, &actions.len().to_string(), button, cx)));
+ }
+ }
crate::menus::Entry::Submenu { .. } => {}
}
}
@@ -3545,4 +3550,52 @@ mod tests {
assert_eq!(label, "Search", "with tabs the command center names the workspace");
std::fs::remove_dir_all(dir).unwrap();
}
+
+ /// debug.contribution.ts Run or Debug... and menuEntryActionViewItem.ts `DropdownWithDefaultActionViewItem`: the
+ /// `editor/title/run` commands draw as a split button whose primary is the first, until another runs from the
+ /// chevron's dropdown and becomes the primary, remembered as `EditorTitleRun_lastActionId`.
+ #[gpui::test]
+ fn editor_title_run_is_a_split_button_whose_dropdown_picks_the_primary(cx: &mut TestAppContext) {
+ use crate::menus::{Entry, MenuId, MenuItem};
+ let (dir, workbench, cx) = workbench_in("editor-title-run", "{}", cx);
+ cx.simulate_resize(gpui::size(gpui::px(1024.), gpui::px(768.)));
+ let file = dir.join("a.txt");
+ std::fs::write(&file, "one\n").unwrap();
+ workbench.update_in(cx, |workbench, window, cx| {
+ for (id, title, order) in [("port.run", "Port Run", 1.), ("port.debug", "Port Debug", 2.)] {
+ let entry = Entry::Command { id: id.into(), precondition: None, toggled: None, alt: None };
+ workbench.menus.push(MenuItem { menu: MenuId::EditorTitleRun, entry, title: title.into(), group: "navigation".into(), order, when: None });
+ workbench.command_icons.insert(id.into(), crate::menus::CommandIcon::Codicon("play".into()));
+ }
+ let entry = Entry::Command { id: "port.preview".into(), precondition: None, toggled: None, alt: None };
+ workbench.menus.push(MenuItem { menu: MenuId::EditorTitle, entry, title: "Preview".into(), group: "navigation".into(), order: 0., when: None });
+ workbench.command_icons.insert("port.preview".into(), crate::menus::CommandIcon::Codicon("open-preview".into()));
+ workbench.open_file(file.clone(), true, window, cx);
+ });
+ cx.run_until_parked();
+ cx.update(|window, _| window.refresh());
+ cx.run_until_parked();
+ assert!(cx.debug_bounds("split-button-primary-port.run").is_some(), "the first command is the primary");
+ let chevron = cx.debug_bounds("split-button-dropdown-EditorTitleRun").expect("the chevron draws").center();
+ let preview = cx.debug_bounds("codicon-open-preview").expect("the next action draws");
+ assert!(cx.debug_bounds("split-button-dropdown-EditorTitleRun").unwrap().right() <= preview.left(), "the split button keeps its width");
+ cx.simulate_click(chevron, gpui::Modifiers::none());
+ cx.run_until_parked();
+ let titles = workbench.read_with(cx, |workbench, _| {
+ let menu = workbench.context_menu.as_ref().expect("the chevron opens the submenu");
+ menu.levels[0].actions.iter().filter_map(|action| match action {
+ crate::menus::MenuAction::Command { title, .. } => Some(title.clone()),
+ _ => None,
+ }).collect::<Vec<_>>()
+ });
+ assert_eq!(titles, ["Port Run", "Port Debug"]);
+ cx.simulate_keystrokes("down down enter");
+ cx.run_until_parked();
+ let stored = workbench.read_with(cx, |workbench, _| workbench.workspace_storage.lock().unwrap().get("EditorTitleRun_lastActionId").map(str::to_string));
+ assert_eq!(stored.as_deref(), Some("port.debug"));
+ cx.update(|window, _| window.refresh());
+ cx.run_until_parked();
+ assert!(cx.debug_bounds("split-button-primary-port.debug").is_some(), "the command run from the dropdown is the primary");
+ std::fs::remove_dir_all(dir).unwrap();
+ }
}
diff --git a/native/crates/app/src/workbench/scm_view.rs b/native/crates/app/src/workbench/scm_view.rs
index cd19e5749cc..0a142484515 100644
--- a/native/crates/app/src/workbench/scm_view.rs
+++ b/native/crates/app/src/workbench/scm_view.rs
@@ -1147,6 +1147,53 @@ impl Workbench {
.child(self.hover_target(gpui::SharedString::from(format!("command-button-hover-{id}")), HoverContent::Text(title), HoverOptions::action_item()))
}
+ /// A split button submenu (menuEntryActionViewItem.ts `DropdownWithDefaultActionViewItem`, `togglePrimaryAction`):
+ /// the command last run from its dropdown, stored per workspace as `<submenu>_lastActionId`, else the first, and
+ /// a chevron that opens the submenu. None when the submenu has no commands.
+ pub(in crate::workbench) fn split_button(&self, submenu: MenuId, submenu_title: String, context: &HashMap<String, Value>, args: Vec<Value>, foreground: Rgba, cx: &mut Context<Self>) -> Option<gpui::Stateful<Div>> {
+ let actions = crate::menus::menu_actions(&self.menus, submenu, context);
+ let storage_key = format!("{submenu:?}_lastActionId");
+ let last = self.workspace_storage.lock().unwrap().get(&storage_key).map(str::to_string);
+ let commands = || actions.iter().filter_map(|action| match action {
+ crate::menus::MenuAction::Command { id, title, .. } => Some((id, title)),
+ _ => None,
+ });
+ let (id, title) = commands().find(|(id, _)| last.as_ref() == Some(*id)).or_else(|| commands().next())?;
+ let primary_selector = format!("split-button-primary-{id}");
+ let primary = self.command_button(id, title.clone(), args.clone(), foreground, cx).debug_selector(move || primary_selector);
+ let bounds = std::rc::Rc::new(std::cell::Cell::new(Bounds::default()));
+ let measured = bounds.clone();
+ let context = context.clone();
+ // shortcut: every group's split button of this submenu shows open, upgrade when two groups show one.
+ let open = self.context_menu.as_ref().is_some_and(|menu| menu.primary_action_storage_key.as_ref() == Some(&storage_key));
+ let hover = self.color("toolbar.hoverBackground");
+ // menuEntryActionViewItem.css: a 16px chevron label pulled 3px under the primary action (`margin-left: -3px`);
+ // absolute in a 13px right padding, as a negative margin zeroes the button's width in taffy.
+ let dropdown = self
+ .icon("chevron-down", 16., 12., foreground)
+ .h(px(22.))
+ .absolute()
+ .right_0()
+ .rounded(px(5.))
+ .when(open, |icon| icon.bg(self.color("toolbar.activeBackground")))
+ .id(gpui::SharedString::from(format!("split-button-dropdown-{submenu:?}")))
+ .debug_selector(move || format!("split-button-dropdown-{submenu:?}"))
+ .cursor_pointer()
+ .hover(move |icon| icon.bg(hover))
+ .on_mouse_down(MouseButton::Left, stop_action_mouse_down)
+ .on_click(cx.listener(move |workbench, _: &ClickEvent, window, cx| {
+ cx.stop_propagation();
+ let actions = crate::menus::menu_actions(&workbench.menus, submenu, &context);
+ workbench.show_context_menu_actions(actions, &context, bounds.get(), args.clone(), window, cx);
+ if let Some(menu) = workbench.context_menu.as_mut() {
+ menu.primary_action_storage_key = Some(storage_key.clone());
+ }
+ }))
+ .child(gpui::canvas(move |element_bounds, _, _| measured.set(element_bounds), |_, _, _, _| {}).absolute().size_full())
+ .child(self.hover_target(gpui::SharedString::from(format!("split-button-hover-{submenu:?}")), HoverContent::Text(submenu_title), HoverOptions::action_item()));
+ Some(div().id(gpui::SharedString::from(format!("split-button-{submenu:?}"))).relative().flex().flex_none().pr(px(13.)).rounded(px(5.)).hover(move |button| button.bg(hover)).child(primary).child(dropdown))
+ }
+
}
/// actionViewItems.ts `EventHelper.stop(e, true)` on mouse down: an action takes no focus and the header under it
diff --git a/port/fixtures/extensions/menus/package.json b/port/fixtures/extensions/menus/package.json
index 0e4513c7a6c..50e5d9acee2 100644
--- a/port/fixtures/extensions/menus/package.json
+++ b/port/fixtures/extensions/menus/package.json
@@ -23,6 +23,16 @@
{
"command": "port.menus.extensionReport",
"title": "Port Extension Action"
+ },
+ {
+ "command": "port.menus.run",
+ "title": "Port Run",
+ "icon": "$(play)"
+ },
+ {
+ "command": "port.menus.debug",
+ "title": "Port Debug",
+ "icon": "$(debug-alt)"
}
],
"menus": {
@@ -38,6 +48,16 @@
"when": "viewContainer == workbench.view.debug"
}
],
+ "editor/title/run": [
+ {
+ "command": "port.menus.run",
+ "group": "navigation@1"
+ },
+ {
+ "command": "port.menus.debug",
+ "group": "navigation@2"
+ }
+ ],
"extension/context": [
{
"command": "port.menus.extensionReport",
diff --git a/port/fixtures/ui-pair/menus/editor-title-run.json b/port/fixtures/ui-pair/menus/editor-title-run.json
new file mode 100644
index 00000000000..7c19b1de9b3
--- /dev/null
+++ b/port/fixtures/ui-pair/menus/editor-title-run.json
@@ -0,0 +1,12 @@
+[
+ {"wait": 15000},
+ {"shot": "title"},
+ {"click": [956, 51], "foreground": true},
+ {"wait": 1000},
+ {"shot": "dropdown"},
+ {"key": "down", "foreground": true},
+ {"key": "down", "foreground": true},
+ {"key": "return", "foreground": true},
+ {"wait": 1500},
+ {"shot": "primary"}
+]
diff --git a/port/ledger.md b/port/ledger.md
index 818ca45549c..341c33ccf8c 100644
--- a/port/ledger.md
+++ b/port/ledger.md
@@ -365,7 +365,7 @@ One row per upstream unit, generated by `bun port/tools/gen-ledger.ts`; mileston
| workbench/parts/views | workbench part | M11 | verified | | Explorer views as panes (view_panes.rs): collapse by mouse and keys, sashes, header drag to reorder with drop overlay, state in workbench.explorer.views.state; no view actions, view menus or hidden views; cargo test -p app view_panes, ui-pair port/results/layout.md; pane headers drawn statically (workbench.rs section_header): no collapse, resize or view actions; verified: ui-pair port/results/references-view.md and every pair of port/results/windows.md (milestone 11 verification): the Explorer panes and contributed views as the reference; Explorer and Source Control views as panes of a ViewPaneContainer (view_panes.rs `PaneContainer`): collapse by mouse and keys, sashes, header drag to reorder with drop overlay, single view merged into the container, header actions, state in the container's storageId; cargo test -p app view_panes scm_container, ui-pair port/results/layout.md and port/fixtures/ui-pair/m11/scm-panes.json (port/notes.md View panes); verified: ui-pair port/results/references-view.md and every pair of port/results/windows.md (milestone 11 verification): the Explorer panes and contributed views as the reference; Run and Debug, Extensions and webview containers still draw section_header rows: no collapse, resize or view actions; welcome buttons draw their `$(icon)`s (cargo test -p app a_welcome_button_draws_its_label_icons; ui-pair port/fixtures/ui-pair/icons/scm-welcome.json: github's Publish to GitHub button with the github codicon as the reference); wrapped text stacks unsnapped 18.2px lines as Chromium (vendor gpui elements/text.rs; cargo test -p app wrapped_lines_keep_their_fractional_line_height): scm-welcome's Publish button 0.5pt from the reference, was 2.5pt; left: the port wraps "Git" of "To learn more about how to use Git" to the next line; a merged view's "..." puts the Views submenu, a separator and the view's own actions (panecomposite.ts `getSecondaryActions`; cargo test -p app a_merged_changes_view_shows_the_views_submenu_in_its_more_actions a_merged_view_without_actions_lists_the_view_toggles_flat) |
| workbench/services/accessibility | workbench service | M19 | verified | | electron-browser accessibilityService.ts over GPUI: screen reader attach follows Electron's `isAccessibilitySupportEnabled` on macOS (VoiceOver, or an assistive app setting AXManualAccessibility or AXEnhancedUserInterface, as cua-driver does; ui-pair screen-reader-detection.json with accessibility support auto shows the prompt in both), the Screen reader usage detected prompt and status entry; port/tools/a11y-check; cargo test -p app accessib; electron-browser accessibilityService.ts over GPUI: screen reader attach follows is_a11y_active, the Screen reader usage detected prompt and status entry; port/tools/a11y-check; cargo test -p app accessib |
| workbench/services/accounts | workbench service | | removed | | no sign-in/AI by decision (port/notes.md); not ported |
-| workbench/services/actions | workbench service | M9 | ported | [3 L] contributes.menus: unmapped ids of menusExtensionPoint.ts, each needing its view's menu first: debug/toolBar (debug_toolbar.rs draws a fixed action list), debug/createConfiguration, testing/item/gutter, testing/profiles/context, testing/item/result, testing/message/context, testing/message/content, webview/context, editor/title/run, modalEditor/editorTitle, editor/inlineCompletions/actions, diffEditor/gutter/selection, multiDiffEditor/content, notebook/cell/execute, notebook/kernelSource, notebook/variables/context, mergeEditor/result/title, comments/comment/editorActions, comments/commentThread/additionalActions, comments/commentThread/title/context, comments/commentThread/comment/context, issue/reporter, titleBar; ports/*, statusBar/remoteIndicator, menuBar/home class 4; touchBar class 2 | contributes.menus and contributes.submenus for editor/context, explorer/context, editor/title/context (menus::extension_menus): cargo test -p app menus explorer_actions; terminal/context, terminal/title/context, debug/callstack/context, debug/variables/context, debug/watch/context, scm/resourceFolder/context and scm/historyItemRef/context (cargo test -p app api_menu_keys_reach_their_menus a_folder_row a_history_item_menu); viewContainer/title on the Run and Debug title with its debugViewlet.ts items (cargo test -p app view_container_title the_debug_container_more_actions; ui-pair `menus/view-container-title.json` with `ARGS=--extensionDevelopmentPath=port/fixtures/extensions/menus`, the rocket and the `...` items match the reference); extension/context in the Manage and row menus after extensionsActions.ts `ManageExtensionAction` (cargo test -p app the_manage_menu_lists_the_extension_context_menu; ui-pair `menus/extension-context.json`, the Copy, Settings and contributed groups match the reference); the AI menu ids (chat/*, chatSessions/*, agents/*, agents/titleBar, editor/context/chat, searchPanel/aiResults/commands) removed by decision (port/notes.md:35); ui-pair README.md Explorer menu (port/results/contextmenu.md); other menu ids wait for their views |
+| workbench/services/actions | workbench service | M9 | ported | [3 L] contributes.menus: unmapped ids of menusExtensionPoint.ts, each needing its view's menu first: debug/toolBar (debug_toolbar.rs draws a fixed action list), debug/createConfiguration, testing/item/gutter, testing/profiles/context, testing/item/result, testing/message/context, testing/message/content, webview/context, modalEditor/editorTitle, editor/inlineCompletions/actions, diffEditor/gutter/selection, multiDiffEditor/content, notebook/cell/execute, notebook/kernelSource, notebook/variables/context, mergeEditor/result/title, comments/comment/editorActions, comments/commentThread/additionalActions, comments/commentThread/title/context, comments/commentThread/comment/context, issue/reporter, titleBar; ports/*, statusBar/remoteIndicator, menuBar/home class 4; touchBar class 2 | contributes.menus and contributes.submenus for editor/context, explorer/context, editor/title/context (menus::extension_menus): cargo test -p app menus explorer_actions; terminal/context, terminal/title/context, debug/callstack/context, debug/variables/context, debug/watch/context, scm/resourceFolder/context and scm/historyItemRef/context (cargo test -p app api_menu_keys_reach_their_menus a_folder_row a_history_item_menu); viewContainer/title on the Run and Debug title with its debugViewlet.ts items (cargo test -p app view_container_title the_debug_container_more_actions; ui-pair `menus/view-container-title.json` with `ARGS=--extensionDevelopmentPath=port/fixtures/extensions/menus`, the rocket and the `...` items match the reference); extension/context in the Manage and row menus after extensionsActions.ts `ManageExtensionAction` (cargo test -p app the_manage_menu_lists_the_extension_context_menu; ui-pair `menus/extension-context.json`, the Copy, Settings and contributed groups match the reference); editor/title/run as the editor title's Run or Debug... split button after menuEntryActionViewItem.ts `DropdownWithDefaultActionViewItem` (cargo test -p app editor_title_run; ui-pair `menus/editor-title-run.json` with `FILE=LICENSE.txt` and an absolute `ARGS=--extensionDevelopmentPath=<repo>/port/fixtures/extensions/menus`: the split button, its open dropdown and the picked primary with the chevron hover match the reference); the AI menu ids (chat/*, chatSessions/*, agents/*, agents/titleBar, editor/context/chat, searchPanel/aiResults/commands) removed by decision (port/notes.md:35); ui-pair README.md Explorer menu (port/results/contextmenu.md); other menu ids wait for their views |
| workbench/services/activity | workbench service | M11 | verified | | activity badges of view containers: view `$setBadge` values, the SCM and Extensions counts and `withProgress` progress badges (300 ms delay, kept 300 ms), numbers summed and shortened as compositeBarActions.ts (workbench/activity.rs; cargo test -p app -- activity progress_at_a_view_container_badges_its_activity_bar_item); `withCompositeProgress` progress bars of a container (side bar or panel title bottom) and of a view (pane header, merged title): `options.delay`, discrete worked of total, infinite, gone on done (progress_at_a_view_container_shows_its_progress_bar_under_the_title); ui-pair `activity-badge.json` on a git folder with two changes: the Source Control badge matches the reference (AE 1808 over the window, port/results/layout.md) |
| workbench/services/agentEditorComments | workbench service | | removed | | no sign-in/AI by decision (port/notes.md); not ported |
| workbench/services/agentHost | workbench service | | removed | | no sign-in/AI by decision (port/notes.md); not ported |