Visual Studio Code, rebuilt in Rust
Rust
use super::super::Workbench;
use gpui::{FontWeight, px, size};
use std::path::Path;
/// The title toolbar's boxes in the reference's DOM at 1024x768 with no folder (port/tools/ref-dom): New Terminal at
/// 841, its profile chevron 3px over it at 860, Split at 880 and the "..." at 932.
#[gpui::test]
fn the_title_toolbar_sits_where_the_reference_lays_it_out(cx: &mut gpui::TestAppContext) {
let app_root = Path::new(env!("VSCODE_SRC")).to_path_buf();
let themes = exthost::scan::scan_extension(&app_root.join("extensions/theme-defaults"), true).unwrap();
let theme = crate::theme::load_theme(&[themes], "Dark Modern").unwrap();
let (workbench, cx) = cx.add_window_view(|_, cx| Workbench::new(theme, app_root.clone(), None, crate::languages::Languages::new(&[]), crate::default_settings(), crate::host_sync::HostSync::new(std::sync::mpsc::channel().0), cx));
cx.simulate_resize(size(px(1024.), px(768.)));
workbench.update_in(cx, |workbench, window, cx| workbench.execute_command("workbench.action.terminal.new", Vec::new(), window, cx));
cx.run_until_parked();
let boxes: Vec<f32> = ["terminal-new", "terminal-new-profile", "terminal-split", "terminal-more"].into_iter().map(|name| f32::from(cx.debug_bounds(name).unwrap().origin.x)).collect();
assert_eq!(boxes, [841., 860., 880., 932.]);
}
/// terminalTabsList.ts: a row 4px in from the pane's edges (modernUI padding.css) with 8px padding (tabs.css), and its label
/// one line of text, `┌ $(terminal) zsh`, so the icon follows the prefix's space.
#[gpui::test]
fn a_tab_row_is_inset_and_its_label_is_one_line_of_text(cx: &mut gpui::TestAppContext) {
let app_root = Path::new(env!("VSCODE_SRC")).to_path_buf();
let themes = exthost::scan::scan_extension(&app_root.join("extensions/theme-defaults"), true).unwrap();
let theme = crate::theme::load_theme(&[themes], "Dark Modern").unwrap();
let (workbench, cx) = cx.add_window_view(|_, cx| Workbench::new(theme, app_root.clone(), None, crate::languages::Languages::new(&[]), crate::default_settings(), crate::host_sync::HostSync::new(std::sync::mpsc::channel().0), cx));
cx.simulate_resize(size(px(1024.), px(768.)));
workbench.update_in(cx, |workbench, window, cx| workbench.execute_command("workbench.action.terminal.new", Vec::new(), window, cx));
workbench.update_in(cx, |workbench, window, cx| workbench.execute_command("workbench.action.terminal.split", Vec::new(), window, cx));
cx.run_until_parked();
let id = workbench.update(cx, |workbench, _| workbench.terminal_view.group_instances()[0][0]);
let list = cx.debug_bounds("terminal-tabs").unwrap();
let row = cx.debug_bounds(format!("terminal-tab-{id}").leak()).unwrap();
let prefix = cx.debug_bounds("terminal-tab-prefix").unwrap();
let icon = cx.debug_bounds("terminal-tab-icon").unwrap();
assert_eq!(f32::from(list.right() - row.right()), 4.);
assert_eq!(f32::from(prefix.origin.x - row.origin.x), 8.);
assert_eq!(icon.origin.x, prefix.right());
}
/// The quiet-fail ui-pair: a 710px panel fits 97 columns in the reference, Menlo 12 at 2x taking 14 device pixels.
#[test]
fn columns_divide_by_the_rendered_cell_not_the_advance() {
let metrics = super::grid::CellMetrics { family: "Menlo".into(), font_size: 12., bold_weight: FontWeight::BOLD, normal_weight: FontWeight::NORMAL, line_height: 1., letter_spacing: 0., cell_width: 7., dom_cell_width: 7.2, cell_height: 16., descent: 3.3, scale: 2. };
assert_eq!(metrics.grid_size(710. - super::grid::GUTTER - super::grid::SCROLLBAR_WIDTH_MODERN, 196.), (97, 12));
}
/// The tab-list ui-pair: modernUI padding.css insets a pane's rows 4px, and the label is `$(icon) title`, a space
/// after the 16px icon where the row's 6px gap was.
#[gpui::test]
fn terminal_tabs_sit_inside_the_list_with_the_title_a_space_after_the_icon(cx: &mut gpui::TestAppContext) {
let app_root = Path::new(env!("VSCODE_SRC")).to_path_buf();
let themes = exthost::scan::scan_extension(&app_root.join("extensions/theme-defaults"), true).unwrap();
let theme = crate::theme::load_theme(&[themes], "Dark Modern").unwrap();
let (workbench, cx) = cx.add_window_view(|_, cx| Workbench::new(theme, app_root.clone(), None, crate::languages::Languages::new(&[]), crate::default_settings(), crate::host_sync::HostSync::new(std::sync::mpsc::channel().0), cx));
cx.simulate_resize(size(px(1024.), px(768.)));
workbench.update_in(cx, |workbench, window, cx| {
workbench.execute_command("workbench.action.terminal.new", Vec::new(), window, cx);
workbench.execute_command("workbench.action.terminal.new", Vec::new(), window, cx);
});
cx.run_until_parked();
let id = workbench.update(cx, |workbench, _| workbench.terminal_view.group_instances()[0][0]);
let list = cx.debug_bounds("terminal-tabs").expect("two terminals show the tabs");
let row = cx.debug_bounds(format!("terminal-tab-{id}").leak()).unwrap();
let title = cx.debug_bounds(format!("terminal-tab-title-{id}").leak()).unwrap();
assert_eq!(row.origin.x - list.origin.x, px(1. + 4.));
assert_eq!(title.origin.x - row.origin.x, px(8. + 16.));
}
/// terminal.css bottom aligns an editor's `.xterm` with no block padding; `.fixed-dims` makes it static, at the top.
/// padding.css gives a modernUI panel's 8px above and below, at the top either way.
#[gpui::test]
fn an_editor_terminal_sits_at_the_bottom_and_a_panel_one_below_its_padding(cx: &mut gpui::TestAppContext) {
let app_root = Path::new(env!("VSCODE_SRC")).to_path_buf();
let themes = exthost::scan::scan_extension(&app_root.join("extensions/theme-defaults"), true).unwrap();
let theme = crate::theme::load_theme(&[themes], "Dark Modern").unwrap();
let (workbench, cx) = cx.add_window_view(|_, cx| Workbench::new(theme, app_root.clone(), None, crate::languages::Languages::new(&[]), crate::default_settings(), crate::host_sync::HostSync::new(std::sync::mpsc::channel().0), cx));
cx.simulate_resize(size(px(1024.), px(768.)));
workbench.update_in(cx, |workbench, window, cx| {
workbench.execute_command("workbench.action.terminal.new", Vec::new(), window, cx);
workbench.execute_command("workbench.action.createTerminalEditor", Vec::new(), window, cx);
});
cx.run_until_parked();
let (panel_top, editor_gap) = workbench.update(cx, |workbench, _| {
let view = &workbench.terminal_view;
let (panel, editor) = (view.group_instances()[0][0], view.editor_instances[0]);
let cell_height = view.metrics.as_ref().unwrap().cell_height;
let editor_instance = view.instance(editor).unwrap();
let pane_height = f32::from(view.pane_bounds[&editor].size.height);
(view.instance(panel).unwrap().grid_top, pane_height - editor_instance.grid_top - editor_instance.term.screen_lines() as f32 * cell_height)
});
assert_eq!(panel_top, super::grid::PADDING_BLOCK);
assert_eq!(editor_gap, 0.);
workbench.update(cx, |workbench, cx| {
let editor = workbench.terminal_view.editor_instances[0];
workbench.terminal_view.instance_mut(editor).unwrap().fixed_cols = Some(200);
cx.notify();
});
cx.run_until_parked();
workbench.update(cx, |workbench, _| assert_eq!(workbench.terminal_view.instance(workbench.terminal_view.editor_instances[0]).unwrap().grid_top, 0.));
}
/// terminalResizeDimensionsOverlay.ts hides `cols x rows` on a 500ms timeout, not on the next frame that happens to paint.
#[gpui::test]
fn the_resize_overlay_hides_half_a_second_after_the_resize(cx: &mut gpui::TestAppContext) {
let app_root = Path::new(env!("VSCODE_SRC")).to_path_buf();
let themes = exthost::scan::scan_extension(&app_root.join("extensions/theme-defaults"), true).unwrap();
let theme = crate::theme::load_theme(&[themes], "Dark Modern").unwrap();
let (workbench, cx) = cx.add_window_view(|_, cx| Workbench::new(theme, app_root.clone(), None, crate::languages::Languages::new(&[]), crate::default_settings(), crate::host_sync::HostSync::new(std::sync::mpsc::channel().0), cx));
cx.simulate_resize(size(px(1024.), px(768.)));
workbench.update_in(cx, |workbench, window, cx| workbench.execute_command("workbench.action.terminal.new", Vec::new(), window, cx));
cx.run_until_parked();
workbench.update(cx, |workbench, cx| {
let instance = &mut workbench.terminal_view.instances[0];
instance.started -= std::time::Duration::from_secs(2);
let id = instance.id;
workbench.show_resize_overlay(id, cx);
});
cx.run_until_parked();
assert!(cx.debug_bounds("terminal-resize-overlay").is_some());
cx.executor().advance_clock(std::time::Duration::from_millis(400));
cx.run_until_parked();
assert!(cx.debug_bounds("terminal-resize-overlay").is_some());
cx.executor().advance_clock(std::time::Duration::from_millis(200));
cx.run_until_parked();
assert!(cx.debug_bounds("terminal-resize-overlay").is_none());
}
/// terminalInstance.ts `attachCustomKeyEventHandler`: with Tab Focus Mode on, Tab is not passed to the terminal and
/// moves the focus; with it off the terminal keeps the focus and takes the key.
#[gpui::test]
fn in_tab_focus_mode_tab_leaves_the_terminal(cx: &mut gpui::TestAppContext) {
let app_root = Path::new(env!("VSCODE_SRC")).to_path_buf();
let themes = exthost::scan::scan_extension(&app_root.join("extensions/theme-defaults"), true).unwrap();
let theme = crate::theme::load_theme(&[themes], "Dark Modern").unwrap();
let (workbench, cx) = cx.add_window_view(|_, cx| Workbench::new(theme, app_root.clone(), None, crate::languages::Languages::new(&[]), crate::default_settings(), crate::host_sync::HostSync::new(std::sync::mpsc::channel().0), cx));
cx.update(|window, _| window.activate_window());
workbench.update_in(cx, |workbench, window, cx| workbench.execute_command("workbench.action.terminal.new", Vec::new(), window, cx));
cx.run_until_parked();
let terminal_focused = |cx: &mut gpui::VisualTestContext| workbench.update_in(cx, |workbench, window, _| workbench.terminal_view.focus.is_focused(window));
assert!(terminal_focused(cx));
cx.simulate_keystrokes("tab");
assert!(terminal_focused(cx));
workbench.update_in(cx, |workbench, window, cx| workbench.execute_command("editor.action.toggleTabFocusMode", Vec::new(), window, cx));
cx.simulate_keystrokes("tab");
assert!(!terminal_focused(cx));
}