Visual Studio Code, rebuilt in Rust
Rust
test(windows): label keys per OS in the remaining workbench tests
rokarturb30b063f1529
diff --git a/native/crates/app/src/workbench/accessible_view.rs b/native/crates/app/src/workbench/accessible_view.rsindex 5ba36b34f05..3ff9c529838 100644--- a/native/crates/app/src/workbench/accessible_view.rs+++ b/native/crates/app/src/workbench/accessible_view.rs@@ -1115,9 +1115,10 @@ mod tests {assert!(help && view_focused);assert_eq!(lines[0], "The application is configured to never be optimized for usage with a Screen Reader.");assert_eq!(lines[2], "You are in a code editor.");- assert!(lines.iter().any(|line| line == "Go to Symbol (Shift+Command+O) to quickly navigate between symbols in the current file."), "{lines:#?}");+ let (go_to_symbol, alt) = if cfg!(target_os = "macos") { ("Shift+Command+O", "Option") } else { ("Control+Shift+O", "Alt") };+ assert!(lines.iter().any(|line| *line == format!("Go to Symbol ({go_to_symbol}) to quickly navigate between symbols in the current file.")), "{lines:#?}");assert!(lines.iter().any(|line| line.contains("(unassigned keybinding)")));- assert_eq!(lines.last().unwrap(), "Configure keybindings for commands that already have assignments (Option+A).");+ assert_eq!(*lines.last().unwrap(), format!("Configure keybindings for commands that already have assignments ({alt}+A)."));cx.simulate_keystrokes("down down end");assert_eq!(state(cx).0.unwrap().2, Position::new(2, "You are in a code editor.".chars().count()));cx.simulate_keystrokes("escape");diff --git a/native/crates/app/src/workbench/activity_bar_menu.rs b/native/crates/app/src/workbench/activity_bar_menu.rsindex 640c0f840e8..2cca20e05cd 100644--- a/native/crates/app/src/workbench/activity_bar_menu.rs+++ b/native/crates/app/src/workbench/activity_bar_menu.rs@@ -599,7 +599,8 @@ mod tests {let item = |title: &str, checked: bool, keybinding: Option<&str>| (title.to_owned(), true, checked, keybinding.map(str::to_owned));let separator = ("---".to_owned(), false, false, None);let rest = [separator.clone(), item("Accounts", false, None), separator, item("Activity Bar Position >", false, None), item("Activity Bar Size >", false, None), item("Move Primary Side Bar Right", false, None)];- let containers = [item("Explorer", true, Some("⇧⌘E")), item("Search", true, Some("⇧⌘F")), item("Source Control", true, Some("⌃⇧G")), item("Run and Debug", true, Some("⇧⌘D")), item("Extensions", true, Some("⇧⌘X"))];+ let keys = if cfg!(target_os = "macos") { ["⇧⌘E", "⇧⌘F", "⌃⇧G", "⇧⌘D", "⇧⌘X"] } else { ["Ctrl+Shift+E", "Ctrl+Shift+F", "Ctrl+Shift+G", "Ctrl+Shift+D", "Ctrl+Shift+X"] };+ let containers = [item("Explorer", true, Some(keys[0])), item("Search", true, Some(keys[1])), item("Source Control", true, Some(keys[2])), item("Run and Debug", true, Some(keys[3])), item("Extensions", true, Some(keys[4]))];assert_eq!(right_click_activity_bar(&workbench, cx), [containers.as_slice(), rest.as_slice()].concat());workbench.update_in(cx, |workbench, window, cx| {diff --git a/native/crates/app/src/workbench/content_hover/tests.rs b/native/crates/app/src/workbench/content_hover/tests.rsindex 08046a813a5..c09be404b22 100644--- a/native/crates/app/src/workbench/content_hover/tests.rs+++ b/native/crates/app/src/workbench/content_hover/tests.rs@@ -131,7 +131,7 @@ fn the_sashes_resize_the_hover_until_its_next_result(cx: &mut TestAppContext) {(bounds.size.width + 2., bounds.size.height + 2.)};let drag = |cx: &mut gpui::VisualTestContext, sash: &'static str, by: gpui::Point<gpui::Pixels>| {- let from = cx.debug_bounds(sash).expect("the sash draws").center();+ let from = cx.debug_bounds(sash).unwrap_or_else(|| panic!("{sash} draws")).center();cx.simulate_mouse_down(from, MouseButton::Left, Modifiers::none());cx.simulate_mouse_move(from + by, Some(MouseButton::Left), Modifiers::none());cx.simulate_mouse_up(from + by, MouseButton::Left, Modifiers::none());diff --git a/native/crates/app/src/workbench/hover/tests.rs b/native/crates/app/src/workbench/hover/tests.rsindex c14d96c8ccd..a9e40da7bf8 100644--- a/native/crates/app/src/workbench/hover/tests.rs+++ b/native/crates/app/src/workbench/hover/tests.rs@@ -3,7 +3,7 @@ use std::sync::{Arc, Mutex};use std::time::Duration;use exthost::scan::scan_extension;-use gpui::{Bounds, Modifiers, MouseButton, TestAppContext, point, px, size};+use gpui::{Bounds, Modifiers, MouseButton, Pixels, TestAppContext, point, px, size};use super::{HoverLayout, HoverOptions, HoverPosition, layout_hover, pointer_shape};use crate::host_sync::HostSync;@@ -160,6 +160,17 @@ fn open_workbench<'a>(name: &str, cx: &'a mut TestAppContext) -> (gpui::Entity<W(workbench, cx)}+/// On Windows the title bar ends at the window controls, three 46px buttons.+fn title_bar_end(width: Pixels) -> Pixels {+ width - px(if cfg!(windows) { 138. } else { 0. })+}++const TOGGLE_PANEL: &str = if cfg!(target_os = "macos") { "Toggle Panel (⌘J)" } else { "Toggle Panel (Ctrl+J)" };+const TOGGLE_SECONDARY_SIDE_BAR: &str = if cfg!(target_os = "macos") { "Toggle Secondary Side Bar (⌥⌘B)" } else { "Toggle Secondary Side Bar (Ctrl+Alt+B)" };++/// toggleTabFocusMode.ts: Ctrl+Shift+M on macOS, Ctrl+M elsewhere.+const TOGGLE_TAB_FOCUS: &str = if cfg!(target_os = "macos") { "ctrl-shift-m" } else { "ctrl-m" };+fn wait(cx: &mut gpui::VisualTestContext, ms: u64) {cx.executor().advance_clock(Duration::from_millis(ms));cx.run_until_parked();@@ -176,7 +187,7 @@ fn shown(workbench: &gpui::Entity<Workbench>, cx: &mut gpui::VisualTestContext)fn clicks_cancel_pending_hovers_and_alt_locks_a_shown_one(cx: &mut TestAppContext) {let (workbench, cx) = open_workbench("hover-lock", cx);let width = cx.update(|window, _| window.viewport_size().width);- let panel = point(width - px(49.), px(18.5));+ let panel = point(title_bar_end(width) - px(49.), px(18.5));let outside = point(width / 2., px(300.));cx.simulate_mouse_move(panel, None, Modifiers::none());@@ -306,8 +317,8 @@ fn a_hover_shows_after_the_delay_and_hides_when_the_pointer_leaves(cx: &mut Testlet (workbench, cx) = open_workbench("hover", cx);let width = cx.update(|window, _| window.viewport_size().width);// Title bar right: 12px inset, 22px items 4px apart; Toggle Secondary Side Bar is last, Toggle Panel before it.- let secondary = point(width - px(23.), px(18.5));- let panel = point(width - px(49.), px(18.5));+ let secondary = point(title_bar_end(width) - px(23.), px(18.5));+ let panel = point(title_bar_end(width) - px(49.), px(18.5));let outside = point(width / 2., px(300.));let shown = |cx: &mut gpui::VisualTestContext| shown(&workbench, cx);@@ -315,12 +326,12 @@ fn a_hover_shows_after_the_delay_and_hides_when_the_pointer_leaves(cx: &mut Testwait(cx, 1499);assert_eq!(shown(cx), None);wait(cx, 1);- assert_eq!(shown(cx).as_deref(), Some("Toggle Secondary Side Bar (⌥⌘B)"));+ assert_eq!(shown(cx).as_deref(), Some(TOGGLE_SECONDARY_SIDE_BAR));// Instant hover: the neighbour within 200ms of the hide shows at once.cx.simulate_mouse_move(panel, None, Modifiers::none());cx.run_until_parked();- assert_eq!(shown(cx).as_deref(), Some("Toggle Panel (⌘J)"));+ assert_eq!(shown(cx).as_deref(), Some(TOGGLE_PANEL));// Leaving hides it once the mouse tracker's 200ms pass.cx.simulate_mouse_move(outside, None, Modifiers::none());@@ -357,7 +368,7 @@ fn a_hover_shows_after_the_delay_and_hides_when_the_pointer_leaves(cx: &mut Testfn a_sticky_hover_stays_until_a_press_outside_it(cx: &mut TestAppContext) {let (workbench, cx) = open_workbench("hover-sticky", cx);let width = cx.update(|window, _| window.viewport_size().width);- let panel = point(width - px(49.), px(18.5));+ let panel = point(title_bar_end(width) - px(49.), px(18.5));let outside = point(width / 2., px(300.));workbench.update_in(cx, |workbench, window, cx| {window.focus(&workbench.status_bar_focus, cx);@@ -385,7 +396,7 @@ fn a_sticky_hover_stays_until_a_press_outside_it(cx: &mut TestAppContext) {fn a_target_under_a_closing_context_menu_gets_its_hover(cx: &mut TestAppContext) {let (workbench, cx) = open_workbench("hover-menu", cx);let width = cx.update(|window, _| window.viewport_size().width);- let panel = point(width - px(49.), px(18.5));+ let panel = point(title_bar_end(width) - px(49.), px(18.5));workbench.update_in(cx, |workbench, window, cx| {let actions = vec![crate::menus::MenuAction::Command { id: "workbench.action.closeAllEditors".into(), title: "Close All".into(), enabled: true, checked: false, alt: None }];workbench.show_context_menu_actions(actions, &Default::default(), Bounds::new(point(px(400.), px(300.)), size(px(0.), px(0.))), Vec::new(), window, cx);@@ -402,7 +413,7 @@ fn a_target_under_a_closing_context_menu_gets_its_hover(cx: &mut TestAppContext)});}wait(cx, 1500);- assert_eq!(shown(&workbench, cx).as_deref(), Some("Toggle Panel (⌘J)"));+ assert_eq!(shown(&workbench, cx).as_deref(), Some(TOGGLE_PANEL));}/// The tab's Unpin Editor after its context menu closes by Escape: the right click hid the hover, the menu left@@ -411,7 +422,7 @@ fn a_target_under_a_closing_context_menu_gets_its_hover(cx: &mut TestAppContext)fn a_right_clicked_target_gets_its_hover_after_the_menu_closes(cx: &mut TestAppContext) {let (workbench, cx) = open_workbench("hover-right-click", cx);let width = cx.update(|window, _| window.viewport_size().width);- let panel = point(width - px(49.), px(18.5));+ let panel = point(title_bar_end(width) - px(49.), px(18.5));cx.simulate_mouse_move(panel, None, Modifiers::none());wait(cx, 500);cx.simulate_mouse_down(panel, MouseButton::Right, Modifiers::none());@@ -429,7 +440,7 @@ fn a_right_clicked_target_gets_its_hover_after_the_menu_closes(cx: &mut TestAppC});}wait(cx, 1500);- assert_eq!(shown(&workbench, cx).as_deref(), Some("Toggle Panel (⌘J)"));+ assert_eq!(shown(&workbench, cx).as_deref(), Some(TOGGLE_PANEL));}/// Shows `markdown` as a managed hover on `target` and draws the measuring frame and the one after it.@@ -735,7 +746,7 @@ fn the_active_editor_tab_takes_the_keyboard_focus_with_its_hover(cx: &mut TestAplet state_of = |name: &str, tab: bool, editor: bool| (name.to_string(), tab, editor);// Past the editor actions toolbar and c.txt's close action.- cx.simulate_keystrokes("ctrl-shift-m shift-tab shift-tab shift-tab");+ cx.simulate_keystrokes(&format!("{TOGGLE_TAB_FOCUS} shift-tab shift-tab shift-tab"));assert_eq!(state(cx), state_of("c.txt", true, false), "Shift+Tab from the editor");cx.simulate_keystrokes("left");assert_eq!(state(cx), state_of("b.txt", true, false));@@ -811,7 +822,7 @@ fn the_tab_close_actions_and_the_editor_actions_toolbar_are_tab_stops(cx: &mut T})};- cx.simulate_keystrokes("ctrl-shift-m");+ cx.simulate_keystrokes(TOGGLE_TAB_FOCUS);let mut backwards = Vec::new();for _ in 0..6 {cx.simulate_keystrokes("shift-tab");diff --git a/native/crates/app/src/workbench/keybindings_editor_view/tests.rs b/native/crates/app/src/workbench/keybindings_editor_view/tests.rsindex 62bbc43a657..61ed61c6486 100644--- a/native/crates/app/src/workbench/keybindings_editor_view/tests.rs+++ b/native/crates/app/src/workbench/keybindings_editor_view/tests.rs@@ -65,7 +65,9 @@ fn the_row_menu_enables_what_the_keybinding_allows() {#[test]fn copy_writes_the_user_settings_form_with_the_when_only_when_set() {- assert_eq!(copied_entry(&entry("cmd+k cmd+s", "", true, "Save")), "{\n \"key\": \"cmd+k cmd+s\",\n \"command\": \"workbench.action.files.save\"\n}");+ // usLayoutResolvedKeybinding.ts `_getUserSettingsLabel`: the Meta key is `cmd`, `win` or `meta` by OS.+ let meta = if cfg!(target_os = "macos") { "cmd" } else if cfg!(windows) { "win" } else { "meta" };+ assert_eq!(copied_entry(&entry("cmd+k cmd+s", "", true, "Save")), format!("{{\n \"key\": \"{meta}+k {meta}+s\",\n \"command\": \"workbench.action.files.save\"\n}}"));assert!(copied_entry(&entry("cmd+s", "editorFocus", true, "Save")).ends_with("\"when\": \"editorFocus\"\n}"));}diff --git a/native/crates/app/src/workbench/quick_access/tests.rs b/native/crates/app/src/workbench/quick_access/tests.rsindex 2c6df5385c5..5c8a6bb7e71 100644--- a/native/crates/app/src/workbench/quick_access/tests.rs+++ b/native/crates/app/src/workbench/quick_access/tests.rs@@ -87,7 +87,8 @@ fn command_palette_runs_an_extension_command_and_remembers_it(cx: &mut TestAppColet item = &input.rows[input.order[0]].item;(item.label.clone(), item.keybinding.clone())});- assert_eq!(row, ("Preferences: Color Theme".to_string(), vec![vec!["⌘".to_string(), "K".to_string()], vec!["⌘".to_string(), "T".to_string()]]));+ let primary = if cfg!(target_os = "macos") { "⌘" } else { "Ctrl" };+ assert_eq!(row, ("Preferences: Color Theme".to_string(), vec![vec![primary.to_string(), "K".to_string()], vec![primary.to_string(), "T".to_string()]]));cx.simulate_keystrokes("secondary-a backspace");cx.simulate_input(">zzzz");@@ -170,20 +171,25 @@ fn help_lists_the_providers_and_shows_the_picked_one(cx: &mut TestAppContext) {cx.simulate_input("?");let (value, placeholder, rows) = picker(cx);assert_eq!((value.as_str(), placeholder.as_str()), ("?", "Type '?' to get help on the actions you can take from here."));+ let keys = if cfg!(target_os = "macos") {+ [r#"[["⌘", "P"]]"#, r#"[["⌃", "G"]]"#, r#"[["⇧", "⌘", "O"]]"#, r#"[["⌘", "T"]]"#, r#"[["⇧", "⌘", "P"]]"#, r#"[["⌥", "⌘", "Tab"]]"#]+ } else {+ [r#"[["Ctrl", "P"]]"#, r#"[["Ctrl", "G"]]"#, r#"[["Ctrl", "Shift", "O"]]"#, r#"[["Ctrl", "T"]]"#, r#"[["Ctrl", "Shift", "P"]]"#, r#"[["Ctrl", "K"], ["Ctrl", "P"]]"#]+ };assert_eq!(rows, [- r#"…|Go to File|[["⌘", "P"]]"#,- r#":|Go to Line/Column|[["⌃", "G"]]"#,- "::|Go to Offset|[]",- r#"@|Go to Symbol in Editor|[["⇧", "⌘", "O"]]"#,- "@:|Go to Symbol in Editor by Category|[]",- r#"#|Go to Symbol in Workspace|[["⌘", "T"]]"#,- r#">|Show and Run Commands|[["⇧", "⌘", "P"]]"#,- "debug |Start Debugging|[]",- r#"edt |Show All Opened Editors By Appearance|[["⌥", "⌘", "Tab"]]"#,- "edt active |Show Editors in Active Group by Most Recently Used|[]",- "edt mru |Show All Opened Editors By Most Recently Used|[]",- "term |Show All Opened Terminals|[]",- "view |Open View|[]",+ format!("…|Go to File|{}", keys[0]),+ format!(":|Go to Line/Column|{}", keys[1]),+ "::|Go to Offset|[]".into(),+ format!("@|Go to Symbol in Editor|{}", keys[2]),+ "@:|Go to Symbol in Editor by Category|[]".into(),+ format!("#|Go to Symbol in Workspace|{}", keys[3]),+ format!(">|Show and Run Commands|{}", keys[4]),+ "debug |Start Debugging|[]".into(),+ format!("edt |Show All Opened Editors By Appearance|{}", keys[5]),+ "edt active |Show Editors in Active Group by Most Recently Used|[]".into(),+ "edt mru |Show All Opened Editors By Most Recently Used|[]".into(),+ "term |Show All Opened Terminals|[]".into(),+ "view |Open View|[]".into(),]);cx.simulate_keystrokes("down enter");assert_eq!(picker(cx).0, ":", "accept shows the picked provider");diff --git a/native/crates/app/src/workbench/repl_notebook/tests.rs b/native/crates/app/src/workbench/repl_notebook/tests.rsindex 205324ae337..25db47fbce1 100644--- a/native/crates/app/src/workbench/repl_notebook/tests.rs+++ b/native/crates/app/src/workbench/repl_notebook/tests.rs@@ -69,7 +69,8 @@ fn a_notebook_shown_as_repl_executes_its_last_cell(cx: &mut TestAppContext) {workbench.update(cx, |workbench, _| workbench.load_keybindings(crate::keybindings::default_keybindings(&[]), dir.join("User/keybindings.json")));assert_eq!(hint(cx), Some(vec!["Enter".to_owned()]));workbench.update(cx, |workbench, _| workbench.update_setting("interactiveWindow.executeWithShiftEnter", json!(true)));- assert_eq!(hint(cx), Some(vec!["⇧".to_owned(), "Enter".to_owned()]));+ let shift = if cfg!(target_os = "macos") { "⇧" } else { "Shift" };+ assert_eq!(hint(cx), Some(vec![shift.to_owned(), "Enter".to_owned()]));workbench.update(cx, |workbench, _| workbench.update_setting("interactiveWindow.executeWithShiftEnter", json!(false)));run(&workbench, "type", vec![json!({ "text": "1+1" })], cx);diff --git a/native/crates/app/src/workbench/title_bar_actions/tests.rs b/native/crates/app/src/workbench/title_bar_actions/tests.rsindex 5f5ff9335af..e78c5ee2faa 100644--- a/native/crates/app/src/workbench/title_bar_actions/tests.rs+++ b/native/crates/app/src/workbench/title_bar_actions/tests.rs@@ -79,7 +79,12 @@ fn the_title_bar_menus_toggle_the_command_center_and_the_layout_controls(cx: &mulet rows = input.order.iter().map(|row| &input.rows[*row]);(input.input_box.value.clone(), rows.map(|row| format!("{}|{}|{:?}", row.item.label, row.item.description.clone().unwrap_or_default(), row.item.keybinding)).collect::<Vec<_>>())});- assert_eq!(picker, (String::new(), vec![r#"Go to File||[["⌘", "P"]]"#.to_string(), r#"Show and Run Commands|>|[["⇧", "⌘", "P"]]"#.into(), r#"Go to Symbol in Editor|@|[["⇧", "⌘", "O"]]"#.into(), "Start Debugging|debug |[]".into(), "More|?|[]".into(), format!("notes.txt|{}|[]", dir.display())]));+ let (go_to_file, commands, symbols) = if cfg!(target_os = "macos") {+ (r#"[["⌘", "P"]]"#, r#"[["⇧", "⌘", "P"]]"#, r#"[["⇧", "⌘", "O"]]"#)+ } else {+ (r#"[["Ctrl", "P"]]"#, r#"[["Ctrl", "Shift", "P"]]"#, r#"[["Ctrl", "Shift", "O"]]"#)+ };+ assert_eq!(picker, (String::new(), vec![format!("Go to File||{go_to_file}"), format!("Show and Run Commands|>|{commands}"), format!("Go to Symbol in Editor|@|{symbols}"), "Start Debugging|debug |[]".into(), "More|?|[]".into(), format!("notes.txt|{}|[]", dir.display())]));cx.simulate_click(point(px(width / 2.), px(20.)), Modifiers::default());assert!(workbench.read_with(cx, |workbench, _| workbench.quick_inputs.current().is_some()), "a press in the quick input over the bar keeps it");cx.simulate_keystrokes("down enter");