Skip to content

Visual Studio Code, rebuilt in Rust

Rust

feat(editor): reveal an opened editor before the modal part

rokarturce08d36f3f56
diff --git a/native/crates/app/src/workbench.rs b/native/crates/app/src/workbench.rs
index 418fabe1939..3a8b268cb26 100644
--- a/native/crates/app/src/workbench.rs
+++ b/native/crates/app/src/workbench.rs
@@ -1183,15 +1183,21 @@ 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) {
+ let revealed = self.reveal_group(&Value::Null, |editor| editor.document().is(scheme, &path));
+ if revealed.is_none() && 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 {
+ if pinned && self.setting("workbench.editor.useModal") != serde_json::json!("all") {
self.close_modal_editor(window, cx);
}
- self.leave_side_group();
- self.leave_locked_group(scheme, &path);
+ match revealed {
+ Some(group) => self.activate_group(group),
+ None => {
+ self.leave_side_group();
+ self.leave_locked_group(scheme, &path);
+ }
+ }
self.open_file_in_active_group(scheme, path, pinned, window, cx);
}
diff --git a/native/crates/app/src/workbench/editor_groups.rs b/native/crates/app/src/workbench/editor_groups.rs
index 85191287200..fa0d2e6d9e4 100644
--- a/native/crates/app/src/workbench/editor_groups.rs
+++ b/native/crates/app/src/workbench/editor_groups.rs
@@ -520,6 +520,29 @@ impl Workbench {
self.activate_group(target);
}
+ /// editorGroupFinder.ts `doFindGroup` for an open without a group or `options.index`: the most recently active group
+ /// with the editor active for `revealIfVisible`, else, for `revealIfOpened` or `workbench.editor.revealIfOpen`, one
+ /// that has it open, a group with it active first. The modal group counts only with `useModal: all`
+ /// (`handleModalEditorPart` sends any other open from it to the main part).
+ pub(super) fn reveal_group(&self, options: &Value, is_editor: impl Fn(&crate::editor::OpenEditor) -> bool) -> Option<u32> {
+ if explicit_group(&options["position"]) || options["index"].is_number() {
+ return None;
+ }
+ let modal_counts = self.setting("workbench.editor.useModal") == json!("all");
+ let groups: Vec<u32> = self.editors.group_ids_mru().into_iter().filter(|group| *group != MODAL_GROUP || modal_counts).collect();
+ let active_in = |group: &u32| {
+ let (editors, active) = self.editors.group_tabs(*group);
+ active.is_some_and(|index| is_editor(&editors[index]))
+ };
+ if options["revealIfVisible"] == json!(true) && let Some(group) = groups.iter().find(|group| active_in(group)) {
+ return Some(*group);
+ }
+ if options["revealIfOpened"] != json!(true) && self.setting("workbench.editor.revealIfOpen") != json!(true) {
+ return None;
+ }
+ let opened_in = |group: &u32| self.editors.group_tabs(*group).0.iter().any(&is_editor);
+ groups.iter().find(|group| active_in(group)).or_else(|| groups.iter().find(|group| opened_in(group))).copied()
+ }
}
/// editorGroupFinder.ts `doFindGroup`: a column (`>= 0`) or SIDE (-2) names the group; ACTIVE (-1) or none leaves it
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 22a2bd747f3..1c809406d04 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,7 +178,10 @@ 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"]) {
+ let revealed = self.reveal_group(options, |editor| self.editors.diffs.get(&editor.model_id).is_some_and(|diff| diff.original == original && diff.modified == modified));
+ if let Some(group) = revealed {
+ self.activate_group(group);
+ } else 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));
diff --git a/native/crates/app/src/workbench/host_requests.rs b/native/crates/app/src/workbench/host_requests.rs
index 10be6622ee4..92aedb01c42 100644
--- a/native/crates/app/src/workbench/host_requests.rs
+++ b/native/crates/app/src/workbench/host_requests.rs
@@ -490,10 +490,13 @@ 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"]) {
+ let revealed = self.reveal_group(options, |editor| editor.document().is(scheme, path));
+ if let Some(group) = revealed {
+ self.activate_group(group);
+ } else 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) {
+ if revealed.is_none() && !options["position"].as_i64().is_some_and(|column| column >= 0) {
self.leave_locked_group(scheme, path);
}
let pinned = options["pinned"] == json!(true);
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 8cb8e96964f..7a75e831bc7 100644
--- a/native/crates/app/src/workbench/modal_editor_group/tests.rs
+++ b/native/crates/app/src/workbench/modal_editor_group/tests.rs
@@ -377,3 +377,27 @@ fn use_modal_all_opens_editors_in_the_modal_part_with_the_diff_change_actions(cx
workbench.read_with(cx, |workbench, _| assert_eq!(workbench.editors.id, 0));
std::fs::remove_dir_all(dir).unwrap();
}
+
+#[gpui::test]
+fn use_modal_all_reveals_an_opened_editor_in_its_group_unless_an_index_is_given(cx: &mut TestAppContext) {
+ let (workbench, cx, dir) = preferences_window(cx, "use-modal-all-reveal");
+ std::fs::write(dir.join("a.txt"), "a").unwrap();
+ std::fs::write(dir.join("b.txt"), "b").unwrap();
+ let a = serde_json::json!({ "scheme": "file", "path": dir.join("a.txt").to_string_lossy() });
+ workbench.update_in(cx, |workbench, window, cx| {
+ workbench.open_file(dir.join("a.txt"), true, window, cx);
+ workbench.update_setting("workbench.editor.useModal", serde_json::json!("all"));
+ workbench.try_show_text_document(&a, &serde_json::json!({ "revealIfOpened": true, "index": 0 }), window, cx).unwrap();
+ assert_eq!(workbench.editors.id, MODAL_GROUP, "an index skips the reveal");
+ workbench.close_modal_group(window, cx);
+ workbench.try_show_text_document(&a, &serde_json::json!({ "revealIfOpened": true }), window, cx).unwrap();
+ assert_eq!(workbench.editors.id, 0, "revealIfOpened finds the group before the modal part");
+ assert!(!workbench.modal_group_open());
+ workbench.update_setting("workbench.editor.revealIfOpen", serde_json::json!(true));
+ workbench.open_file(dir.join("b.txt"), true, window, cx);
+ assert_eq!(workbench.editors.id, MODAL_GROUP, "an editor open nowhere goes to the modal part");
+ workbench.open_file(dir.join("a.txt"), true, window, cx);
+ assert_eq!(workbench.editors.id, 0, "workbench.editor.revealIfOpen reveals it in its group");
+ });
+ std::fs::remove_dir_all(dir).unwrap();
+}
diff --git a/port/fixtures/ui-pair/m8/modal-all.json b/port/fixtures/ui-pair/m8/modal-all.json
new file mode 100644
index 00000000000..af6c5427f00
--- /dev/null
+++ b/port/fixtures/ui-pair/m8/modal-all.json
@@ -0,0 +1,10 @@
+[
+ {"wait": 15000},
+ {"hotkey": ["cmd", "p"], "foreground": true},
+ {"wait": 800},
+ {"type": "notes.txt"},
+ {"wait": 1500},
+ {"key": "return", "foreground": true},
+ {"wait": 2500},
+ {"shot": "modal-all"}
+]
diff --git a/port/ledger.md b/port/ledger.md
index 394d9a96ef4..f62b2fc2a96 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` 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/editor | workbench part | M8 | verified | | 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 use_modal_all_reveals_an_opened_editor_in_its_group_unless_an_index_is_given 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 |