Skip to content

Visual Studio Code, rebuilt in Rust

Rust

feat(editor): open editors in the modal part with useModal all

rokarture46edae20fd7
diff --git a/native/crates/app/src/workbench.rs b/native/crates/app/src/workbench.rs
index 50b33e499ec..ed0db66c6ec 100644
--- a/native/crates/app/src/workbench.rs
+++ b/native/crates/app/src/workbench.rs
@@ -1183,6 +1183,9 @@ impl Workbench {
/// `open_file` of a resource of a disk provider (`on_disk`): a file or a user data file.
pub(super) fn open_disk_resource(&mut self, scheme: &str, path: PathBuf, pinned: bool, window: &mut Window, cx: &mut Context<Self>) {
+ if self.enter_modal_group_for_all(window, cx) {
+ return self.open_file_in_active_group(scheme, path, pinned, window, cx);
+ }
// editorGroupFinder.ts `handleModalEditorPart`: an editor opened without preserveFocus closes the modal.
if pinned {
self.close_modal_editor(window, cx);
diff --git a/native/crates/app/src/workbench/editor_groups.rs b/native/crates/app/src/workbench/editor_groups.rs
index 0879eef43de..85191287200 100644
--- a/native/crates/app/src/workbench/editor_groups.rs
+++ b/native/crates/app/src/workbench/editor_groups.rs
@@ -520,6 +520,15 @@ impl Workbench {
self.activate_group(target);
}
+}
+
+/// editorGroupFinder.ts `doFindGroup`: a column (`>= 0`) or SIDE (-2) names the group; ACTIVE (-1) or none leaves it
+/// to the finder.
+pub(super) fn explicit_group(column: &Value) -> bool {
+ column.as_i64().is_some_and(|column| column >= 0 || column == -2)
+}
+
+impl Workbench {
fn add_to_grid(&mut self, reference: u32, direction: Direction, group: u32) {
// auxiliaryEditorPart.ts `getAddGroupLocation`: a compact editor window adds groups to the main part.
if self.part_of_group(reference).is_some_and(|part| self.is_compact_part(part)) {
diff --git a/native/crates/app/src/workbench/editor_view/diff_editor_view.rs b/native/crates/app/src/workbench/editor_view/diff_editor_view.rs
index 1422aa58efa..22a2bd747f3 100644
--- a/native/crates/app/src/workbench/editor_view/diff_editor_view.rs
+++ b/native/crates/app/src/workbench/editor_view/diff_editor_view.rs
@@ -178,6 +178,9 @@ impl Workbench {
/// opens (a preview unless `pinned` or `preview: false`).
pub(in crate::workbench) fn show_diff_editor(&mut self, original: Side, modified: Side, label: Option<String>, options: &Value, window: &mut Window, cx: &mut Context<Self>) {
self.activate_column(&options["position"], None);
+ if !crate::workbench::editor_groups::explicit_group(&options["position"]) {
+ self.enter_modal_group_for_all(window, cx);
+ }
let existing = self.editors.editors.iter().position(|editor| self.editors.diffs.get(&editor.model_id).is_some_and(|diff| diff.original == original && diff.modified == modified));
let pinned = options["pinned"] == json!(true) || options["preview"] == json!(false);
match existing {
@@ -513,7 +516,7 @@ impl Workbench {
/// The diff editor below the breadcrumbs: side by side the original pane, its sash and the modified code editor,
/// inline the modified code editor alone, then the diff overview ruler.
- pub(super) fn diff_editor_body(&self, input: &DiffInput, modified: &OpenEditor, window: &mut Window, cx: &mut Context<Self>) -> Div {
+ pub(in crate::workbench) fn diff_editor_body(&self, input: &DiffInput, modified: &OpenEditor, window: &mut Window, cx: &mut Context<Self>) -> Div {
let part_width = self.diff_part_width.clone();
let measure = canvas(move |bounds, _, _| part_width.set(f32::from(bounds.size.width)), |_, _, _, _| {}).absolute().inset_0();
let mut body = div().flex_1().min_h_0().relative().flex().child(measure);
diff --git a/native/crates/app/src/workbench/host_requests.rs b/native/crates/app/src/workbench/host_requests.rs
index e9ec4054869..10be6622ee4 100644
--- a/native/crates/app/src/workbench/host_requests.rs
+++ b/native/crates/app/src/workbench/host_requests.rs
@@ -490,6 +490,9 @@ impl Workbench {
}
let (scheme, ref path) = uri_parts(uri)?;
self.activate_column(&options["position"], Some((scheme, path)));
+ if !super::editor_groups::explicit_group(&options["position"]) {
+ self.enter_modal_group_for_all(window, cx);
+ }
if !options["position"].as_i64().is_some_and(|column| column >= 0) {
self.leave_locked_group(scheme, path);
}
diff --git a/native/crates/app/src/workbench/keybindings_editor_view.rs b/native/crates/app/src/workbench/keybindings_editor_view.rs
index b22cea38935..1a6c11c1ff6 100644
--- a/native/crates/app/src/workbench/keybindings_editor_view.rs
+++ b/native/crates/app/src/workbench/keybindings_editor_view.rs
@@ -938,11 +938,20 @@ impl Workbench {
let top = ((window_height - height) / 2.).max(TITLE_BAR_HEIGHT).round();
let editor_height = height - 2. - MODAL_HEADER_HEIGHT - 1.;
let editor = editor(self, width - 2., editor_height, window, cx);
- // The editor actions see the context of the modal group's text editor.
- let context = match header.resource {
- Some(_) => self.with_group(crate::editor::MODAL_GROUP, |workbench| workbench.key_context(window)),
- None => self.key_context(window),
+ // The editor actions see the context of the modal group's text editor. editor.contribution.ts
+ // `enableInModalMode`: of the built-in editor title actions only a diff's Previous and Next Change.
+ let (context, diff_actions) = match header.resource {
+ Some(_) => self.with_group(crate::editor::MODAL_GROUP, |workbench| (workbench.key_context(window), workbench.diff_title_actions(cx))),
+ None => (self.key_context(window), Vec::new()),
};
+ let diff_actions: Vec<_> = diff_actions.into_iter().filter_map(|(order, action)| {
+ let (title, command) = match order {
+ 10. => ("Previous Change", "workbench.action.compareEditor.previousChange"),
+ 11. => ("Next Change", "workbench.action.compareEditor.nextChange"),
+ _ => return None,
+ };
+ Some((order, title.to_string(), action.debug_selector(move || format!("modal-editor-action-{command}"))))
+ }).collect();
let modal = div()
.id("modal-editor")
.debug_selector(|| "modal-editor".into())
@@ -964,7 +973,7 @@ impl Workbench {
// --vscode-shadow-xl blurs 20px; GPUI's blur_radius is the sigma, half the CSS blur.
.shadow(vec![BoxShadow { color: rgba(0x00000026).into(), offset: point(px(0.), px(0.)), blur_radius: px(10.), spread_radius: px(0.), inset: false }])
.on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation())
- .child(self.modal_header(header, context, cx))
+ .child(self.modal_header(header, context, diff_actions, cx))
.child(editor);
let block = div()
.id("modal-editor-block")
@@ -984,9 +993,10 @@ impl Workbench {
}
/// `.modal-editor-header`: the editor's icon and title, and the `ModalEditorTitle` actions.
- fn modal_header(&self, header: ModalHeader, context: HashMap<String, Value>, cx: &mut Context<Self>) -> impl IntoElement + use<> {
+ fn modal_header(&self, header: ModalHeader, context: HashMap<String, Value>, diff_actions: Vec<(f64, String, gpui::Stateful<gpui::Div>)>, cx: &mut Context<Self>) -> impl IntoElement + use<> {
let foreground = self.foreground_or("titleBar.activeForeground");
let (mut editor_actions, more) = self.modal_editor_menu_actions(&header.args, context, foreground, cx);
+ editor_actions.extend(diff_actions);
let action = |name: &'static str, title: &'static str, command: &'static str, args: Vec<Value>| {
self.icon(name, 22., 16., foreground)
.id(command)
diff --git a/native/crates/app/src/workbench/modal_editor_group.rs b/native/crates/app/src/workbench/modal_editor_group.rs
index 4bb8dafaaea..1c75bf669ca 100644
--- a/native/crates/app/src/workbench/modal_editor_group.rs
+++ b/native/crates/app/src/workbench/modal_editor_group.rs
@@ -1,4 +1,4 @@
-//! The modal editor part (modalEditorPart.ts) for text editors, the Settings, Keyboard Shortcuts, Profiles and Workspace Trust editors and Images
+//! The modal editor part (modalEditorPart.ts) for text and diff editors, the Settings, Keyboard Shortcuts, Profiles and Workspace Trust editors and Images
//! Preview: preferencesService.ts opens those editors and the settings and keybindings JSON files, and image_carousel.rs its editor, in `MODAL_GROUP` unless `workbench.editor.useModal` is `off`. The group lives outside the grid
//! like the panel's; the part shows its active editor without tabs, breadcrumbs or editor actions (`showTabs: none`,
//! `editorActionsLocation: hidden`) under the header with the editor's label, and closes with its last editor.
@@ -60,6 +60,16 @@ impl Workbench {
self.editors_changed(cx);
}
+ /// editorGroupFinder.ts `doFindGroup`: with `workbench.editor.useModal: all` an editor opened without a group
+ /// goes to the modal part. Returns whether it does.
+ pub(super) fn enter_modal_group_for_all(&mut self, window: &Window, cx: &App) -> bool {
+ if self.setting("workbench.editor.useModal") != json!("all") {
+ return false;
+ }
+ self.enter_modal_group(window, cx);
+ true
+ }
+
fn enter_modal_group(&mut self, window: &Window, cx: &App) {
if !self.modal_group_open() {
self.editor_groups.modal_previous_focus = window.focused(cx);
@@ -255,6 +265,9 @@ impl Workbench {
if workbench.shows_webview(editor) {
return div().flex_1().min_h_0().flex().flex_col().child(workbench.webview_editor_body(editor));
}
+ if let Some(diff) = workbench.editors.active_diff() {
+ return div().flex_1().min_h_0().flex().flex_col().child(workbench.diff_editor_body(diff, diff.modified_editor.as_ref().unwrap_or(editor), window, cx));
+ }
let breadcrumbs = (workbench.setting("breadcrumbs.enabled") != json!(false)).then(|| workbench.breadcrumbs(editor, cx));
let part = div().flex_1().min_h_0().flex().flex_col().children(breadcrumbs);
match secondary {
diff --git a/native/crates/app/src/workbench/modal_editor_group/tests.rs b/native/crates/app/src/workbench/modal_editor_group/tests.rs
index a2415041a41..8cb8e96964f 100644
--- a/native/crates/app/src/workbench/modal_editor_group/tests.rs
+++ b/native/crates/app/src/workbench/modal_editor_group/tests.rs
@@ -344,3 +344,36 @@ fn the_settings_editor_joins_the_keyboard_shortcuts_editor(cx: &mut TestAppConte
assert!(workbench.keybindings_editor.search_focus.is_focused(window));
});
}
+
+/// editorGroupFinder.ts `doFindGroup` with `workbench.editor.useModal: all`: a file and a diff open in the modal part,
+/// whose header shows the diff's Previous and Next Change (editor.contribution.ts `enableInModalMode`); a diff at an
+/// explicit column stays in the grid.
+#[gpui::test]
+fn use_modal_all_opens_editors_in_the_modal_part_with_the_diff_change_actions(cx: &mut TestAppContext) {
+ let (workbench, cx, dir) = preferences_window(cx, "use-modal-all");
+ std::fs::write(dir.join("a.txt"), "one\ntwo").unwrap();
+ std::fs::write(dir.join("b.txt"), "one\nTWO").unwrap();
+ let uri = |name: &str| serde_json::json!({ "scheme": "file", "path": dir.join(name).to_string_lossy() });
+ workbench.update_in(cx, |workbench, window, cx| {
+ workbench.update_setting("workbench.editor.useModal", serde_json::json!("all"));
+ workbench.open_file(dir.join("a.txt"), true, window, cx);
+ assert_eq!(workbench.editors.id, MODAL_GROUP);
+ drop(workbench.execute_command("_workbench.diff", vec![uri("a.txt"), uri("b.txt")], window, cx));
+ });
+ cx.run_until_parked();
+ workbench.read_with(cx, |workbench, _| {
+ assert_eq!(workbench.editors.id, MODAL_GROUP);
+ assert!(workbench.editors.active_diff().is_some());
+ assert!(workbench.editors.group_tabs(0).0.is_empty());
+ });
+ let previous = cx.debug_bounds("modal-editor-action-workbench.action.compareEditor.previousChange").expect("Previous Change is drawn");
+ let next = cx.debug_bounds("modal-editor-action-workbench.action.compareEditor.nextChange").expect("Next Change is drawn");
+ assert!(previous.left() < next.left(), "order 10 before order 11");
+ workbench.update_in(cx, |workbench, window, cx| {
+ workbench.close_modal_group(window, cx);
+ drop(workbench.execute_command("_workbench.diff", vec![uri("a.txt"), uri("b.txt"), serde_json::json!(null), serde_json::json!([0])], window, cx));
+ });
+ cx.run_until_parked();
+ workbench.read_with(cx, |workbench, _| assert_eq!(workbench.editors.id, 0));
+ std::fs::remove_dir_all(dir).unwrap();
+}
diff --git a/port/ledger.md b/port/ledger.md
index c271d994024..4af13ea69c7 100644
--- a/port/ledger.md
+++ b/port/ledger.md
@@ -409,7 +409,7 @@ One row per upstream unit, generated by `bun port/tools/gen-ledger.ts`; mileston
| workbench/parts/banner | workbench part | M11 | verified | | workbench/banner.rs (bannerPart.ts): one item by priority, icon, message with ellipsis, link actions, Close Banner; Focus Banner, `bannerFocused`, arrow keys through the links and the close button, Enter and Space on them. `cargo test -p app banner`; verified: ui-pair banner.json vs the reference (port/results/windows.md, milestone 11 verification) |
| workbench/parts/chat | workbench part | | removed | | no sign-in/AI by decision (port/notes.md); not ported |
| workbench/parts/dialogs | workbench part | M11 | verified | | workbench/dialog_view.rs custom dialog, used for every message box with `window.dialogStyle: custom` (severity codicons, plain detail); cargo test -p app dialogs; verified: ui-pair dialogs.json `custom-modal` vs the reference (port/results/windows.md, milestone 11 verification): size, buttons in macOS order, Close Dialog; its buttons and Close Dialog are accessibility buttons named by their labels (dialog.ts monaco Buttons, the close action's aria-label): port/tools/update-check pre-release presses "Trust Publisher & Install" through them |
-| workbench/parts/editor | workbench part | M8 | ported | [3 S] keybindings_editor_view.rs `modal_header`: editor.contribution.ts `enableInModalMode` items (Previous/Next Change, Reopen as Text) are missing; their `when` needs a text or custom text diff editor in the modal part, which only `workbench.editor.useModal` `all` opens there, and the port opens no editor modal for `all` | breadcrumbs, tab strip, text editor, groups, title menus, terminal editors, `workbench.editor.showTabs` and `editorActionsLocation` (workbench/editor_view.rs, workbench/editor_menus.rs, editor_type_picker.rs, scroll_locking.rs; port/notes.md milestone 5): cargo test -p app workbench::breadcrumbs editor::tests keys_and_typed_text_edit_the_focused_editor_and_reach_the_host editor_menus workbench_open diff_editor editor_groups editor_grid scroll_locking the_grid_and_its_editors_come_back_from_workspace_storage the_wait_marker_waits_for_the_dirty_file_to_be_saved editor_type_picker custom_editors terminal_editor icon_select_box previews_off_pins_every_opened_editor tab_labels_keep show_tabs_picks_the_title_control_and_zen_mode_enforces_its_own show_tabs_none_moves_the_editor_actions_into_the_title_bar the_tab_bar_menu_switches_the_tabs_mode the_editor_actions_toggle_restores_the_hidden_location menubar the_keyboard_focuses_moves_through_and_reveals_the_breadcrumbs the_modal_header_shows_the_modal_editor_title_menu; ui-pair m8/breadcrumbs-pickers.json, m12/editor-type.json, m12/editor-type-second-start.json, m11/editor-menus.json, m11/watermark-tips.json, m12/terminal-editor.json, m12/terminal-pickers.json, m12/terminal-tab-list-menu.json, icons/seti.json, show-tabs.json, menus/modal-editor-title.json; pixel-check file window (port/results/pixels.md milestone 4); port/results/contextmenu.md, port/results/auxiliary-windows.md, port/results/api-tests.md |
+| workbench/parts/editor | workbench part | M8 | ported | [3 S] keybindings_editor_view.rs `modal_header`: editor.contribution.ts `enableInModalMode` Reopen as Text is missing; its `when` (`activeCustomEditorTextDiff`) needs a custom editor on a diff input (customEditors.ts `getActiveCustomEditorTextDiff`), and the port opens every diff in the text diff editor. `useModal: all` opens an editor without a group in the modal part, without editorGroupFinder.ts's `revealIfOpened` and `options.index` cases | breadcrumbs, tab strip, text editor, groups, title menus, terminal editors, `workbench.editor.showTabs` and `editorActionsLocation` (workbench/editor_view.rs, workbench/editor_menus.rs, editor_type_picker.rs, scroll_locking.rs; port/notes.md milestone 5): cargo test -p app workbench::breadcrumbs editor::tests use_modal_all_opens_editors_in_the_modal_part keys_and_typed_text_edit_the_focused_editor_and_reach_the_host editor_menus workbench_open diff_editor editor_groups editor_grid scroll_locking the_grid_and_its_editors_come_back_from_workspace_storage the_wait_marker_waits_for_the_dirty_file_to_be_saved editor_type_picker custom_editors terminal_editor icon_select_box previews_off_pins_every_opened_editor tab_labels_keep show_tabs_picks_the_title_control_and_zen_mode_enforces_its_own show_tabs_none_moves_the_editor_actions_into_the_title_bar the_tab_bar_menu_switches_the_tabs_mode the_editor_actions_toggle_restores_the_hidden_location menubar the_keyboard_focuses_moves_through_and_reveals_the_breadcrumbs the_modal_header_shows_the_modal_editor_title_menu; ui-pair m8/breadcrumbs-pickers.json, m12/editor-type.json, m12/editor-type-second-start.json, m11/editor-menus.json, m11/watermark-tips.json, m12/terminal-editor.json, m12/terminal-pickers.json, m12/terminal-tab-list-menu.json, icons/seti.json, show-tabs.json, menus/modal-editor-title.json; pixel-check file window (port/results/pixels.md milestone 4); port/results/contextmenu.md, port/results/auxiliary-windows.md, port/results/api-tests.md |
| workbench/parts/notifications | workbench part | M11 | verified | | workbench/notifications_view.rs: toasts (3 at most, purge 10/12/15s unless sticky, focused or hovered, spam protection), notifications center (Clear All, Do Not Disturb menu with per-source filters, Hide), rows with expand, collapse, clear, More Actions, buttons, links, Copy Text, double-click toggle; status bar bell states and tooltips; notificationsCommands.ts commands and context keys; geometry from the reference DOM (port/tools/ref-dom); cargo test -p app notifications_view; `workbench.notifications.position` (bottom right, bottom left, top right with the title bar bell); no toast animation, no screen reader announcements; verified: ui-pair messages.json `center`, `progress` vs the reference (port/results/windows.md, milestone 11 verification) |
| workbench/parts/panel | workbench part | M11 | verified | | bottom centered card, view tabs from register_panel_view with the "..." overflow of compositeBar.ts (cargo test -p app workbench::panel::, ui-pair port/results/problems.md), `<view id>.focus` per view, Maximize/Restore, Close, Cmd+J, active view in workspace storage; Problems, Output, Debug Console, Test Results (`hideIfEmpty`) and Terminal views with their title actions (cargo test -p app editor_groups the_output_view_shows_in_the_panel, output_view, the_debug_console_and_test_results_are_panel_views, terminal); part_grid tests, ui-pair port/results/layout.md; no panel position or alignment change, no Views and More Actions menu; verified: ui-pair port/results/problems.md (milestone 11 verification): tabs, "..." overflow and the filter box as the reference; tabs at Chromium's fractional text widths (the Problems tab with its badge was 2px wider: GPUI rounds a text element's width up), the filter in the view below 600px of width (`shouldShowFilterInHeader`) |
| workbench/parts/partGrid | workbench part | M11 | verified | | workbench/layout.rs grid on split_view.rs (splitview.ts priorities, snap, visibility), workbench/part_grid.rs sashes, hidden parts, sizes and visibility in LayoutStateModel storage keys: cargo test -p app layout part_grid split_view (reference geometry at 1024x768, Cmd+B for the next open, sash drag, snap); ui-pair grid steps, port/results/layout.md |