Skip to content

Visual Studio Code, rebuilt in Rust

Rust

fix(scm): place tree folder rows a level in with their guides, badge and hover

rokartur5e5a056816fa
diff --git a/native/crates/app/src/workbench/scm_actions/tests.rs b/native/crates/app/src/workbench/scm_actions/tests.rs
index 6a71afec203..33ca8dd2021 100644
--- a/native/crates/app/src/workbench/scm_actions/tests.rs
+++ b/native/crates/app/src/workbench/scm_actions/tests.rs
@@ -299,6 +299,27 @@ fn a_folder_row_shows_the_resource_folder_menu_with_its_resources(cx: &mut TestA
});
}
+/// abstractTree.ts indent guides in the Changes view: the group's children draw its guide 16px in from the rows'
+/// 4px modernUI inset.
+#[gpui::test]
+fn the_changes_tree_draws_indent_guides(cx: &mut TestAppContext) {
+ let (workbench, _receiver, cx) = workbench_in("scm-folder-guides", cx);
+ cx.simulate_resize(gpui::size(gpui::px(1024.), gpui::px(768.)));
+ request(&workbench, cx, "$registerSourceControl", register(0, "/w/repo"));
+ let raw = |handle: u64, path: &str| json!([handle, { "scheme": "file", "path": path }, [null, null], "Modified", false, false, "", null, null, null]);
+ let groups = json!([[2, "workingTree", "Changes", {}, false]]);
+ request(&workbench, cx, "$registerGroups", vec![json!(0), groups, json!([[2, [[0, 0, [raw(1, "/w/repo/src/a.ts"), raw(2, "/w/repo/c.ts")]]]]])]);
+ workbench.update_in(cx, |workbench, window, cx| {
+ drop(workbench.execute_command("workbench.scm.action.setTreeViewMode", Vec::new(), window, cx));
+ drop(workbench.execute_command("workbench.view.scm", Vec::new(), window, cx));
+ workbench.set_part_hidden(crate::workbench::layout::Part::SideBar, false, cx);
+ });
+ cx.run_until_parked();
+ let group = cx.debug_bounds("scm-group-0-2").expect("the view shows the group");
+ let guide = cx.debug_bounds("tree-guide").expect("the group's children draw its guide");
+ assert_eq!(f32::from(guide.origin.x - group.origin.x), 4. + 16.);
+}
+
/// scmViewPane.ts `onListContextMenu` and util.ts `collectContextMenuActions`: a repository, resource group or
/// resource row's menu drops the `inline` group its row shows as buttons.
#[gpui::test]
diff --git a/native/crates/app/src/workbench/scm_tree.rs b/native/crates/app/src/workbench/scm_tree.rs
index a10e4d40756..a0b648696ec 100644
--- a/native/crates/app/src/workbench/scm_tree.rs
+++ b/native/crates/app/src/workbench/scm_tree.rs
@@ -53,12 +53,23 @@ impl Workbench {
let foreground = self.foreground_or("sideBar.foreground");
let key = (provider.handle, group.handle, path);
let expanded = !self.scm.collapsed_folders.contains(&key);
- let icon = self.file_icons.as_ref().and_then(|icons| icons.folder_icon(FolderIcon { path: Path::new(&label), is_root: false, expanded }, self.theme.kind, 13., ROW_HEIGHT, foreground)).unwrap_or_else(|| div().w(px(16.)));
+ let icon = self.file_icons.as_ref().and_then(|icons| icons.folder_icon(FolderIcon { path: Path::new(&label), is_root: false, expanded }, self.theme.kind, 13., ROW_HEIGHT, foreground));
+ let label_margin = if icon.is_some() { 6. } else { 3. };
let id = gpui::SharedString::from(format!("scm-folder-{}-{}-{}", provider.handle, group.handle, key.2.display()));
let context = self.scm_context(provider, Some(group), None, window);
let root = PathBuf::from(provider.root_uri["path"].as_str().unwrap_or_default());
let paths: Vec<PathBuf> = group.resources.iter().map(resource_path).collect();
- let args: Vec<Value> = folder_resources(&root.join(&key.2), &paths).into_iter().map(|index| Self::resource_arg(provider, group, &group.resources[index])).collect();
+ let folder = root.join(&key.2);
+ let args: Vec<Value> = folder_resources(&folder, &paths).into_iter().map(|index| Self::resource_arg(provider, group, &group.resources[index])).collect();
+ // renderCompressedElements: `fileDecorations: { colors: false, badges: true }`; labels.ts titles the label with
+ // its path, then the decoration's tooltip.
+ let decoration = self.file_decoration(&folder, true);
+ let badge = self.decoration_badge(decoration.as_ref(), foreground);
+ let title = match decoration.as_ref().and_then(|decoration| decoration.tooltip.as_deref()) {
+ Some(tooltip) => format!("{} \u{2022} {tooltip}", crate::quick_input::path_label(&folder, None)),
+ None => crate::quick_input::path_label(&folder, None),
+ };
+ let hover = self.hover_target(gpui::SharedString::from(format!("{id}-hover")), super::hover::HoverContent::Text(title), super::hover::HoverOptions::mouse());
let actions = self.inline_actions(MenuId::ScmResourceFolderContext, None, &context, args.clone(), foreground, cx);
let selector = id.to_string();
div()
@@ -66,7 +77,9 @@ impl Workbench {
.debug_selector(move || selector)
.group(id.clone())
.h(px(ROW_HEIGHT))
- .pl(px(INDENT * (1 + depth) as f32))
+ .relative()
+ // A group's children: one tree level (8px) further in than the group row's twistie.
+ .pl(px(INDENT * (2 + depth) as f32 + 7.))
.pr(px(12.))
.flex()
.items_center()
@@ -82,10 +95,13 @@ impl Workbench {
let actions = crate::menus::menu_group_actions(&workbench.menus, MenuId::ScmResourceFolderContext, &context, |group| group != "inline");
workbench.show_context_menu_actions(actions, &context, Bounds::new(event.position, Default::default()), args.clone(), window, cx);
}))
+ .child(hover)
.child(self.icon(if expanded { "chevron-down" } else { "chevron-right" }, TWISTIE, 16., foreground))
- .child(icon.mr(px(6.)))
- .child(div().flex_1().min_w_0().overflow_hidden().whitespace_nowrap().child(label))
+ // explorerViewer.ts as the Explorer: a theme without folder icons (Seti) puts the label right after the twistie.
+ .children(icon.map(|icon| icon.ml(px(3.))))
+ .child(div().flex_1().min_w_0().ml(px(label_margin)).overflow_hidden().whitespace_nowrap().child(label))
.child(div().invisible().group_hover(id, |actions| actions.visible()).child(actions))
+ .children(badge)
}
pub(super) fn scm_tree_mode(&self) -> bool {
diff --git a/native/crates/app/src/workbench/scm_view.rs b/native/crates/app/src/workbench/scm_view.rs
index eb8e8694517..d78fbab3c9d 100644
--- a/native/crates/app/src/workbench/scm_view.rs
+++ b/native/crates/app/src/workbench/scm_view.rs
@@ -26,6 +26,13 @@ pub(super) const ROW_HEIGHT: f32 = 22.;
pub(super) const INDENT: f32 = 8.;
pub(super) const TWISTIE: f32 = 16.;
+/// A row of the Changes view with its tree depth (abstractTree.ts, from 1) and whether it is the selected one.
+struct ScmRow {
+ depth: usize,
+ selected: bool,
+ element: gpui::AnyElement,
+}
+
/// scmViewService.ts `ISCMViewServiceState` but its sort key: the repositories by `getProviderStorageKey` and the
/// shown ones by their index there.
struct PreviousState {
@@ -638,17 +645,24 @@ impl Workbench {
let body = match providers.is_empty() {
true => div().flex().flex_col().children(self.view_welcome(super::views_welcome::SCM_VIEW, window, cx)).into_any_element(),
false => {
- let mut rows: Vec<gpui::AnyElement> = Vec::new();
+ let mut rows = Vec::new();
for provider in &providers {
if show_repositories {
- rows.push(self.scm_repository_row(provider, providers.len(), window, cx).into_any_element());
+ rows.push(ScmRow { depth: 1, selected: false, element: self.scm_repository_row(provider, providers.len(), window, cx).into_any_element() });
if self.scm.collapsed_repositories.contains(&provider.handle) {
continue;
}
}
self.push_scm_repository_children(&mut rows, provider, providers.len(), usize::from(show_repositories), window, cx);
}
- div().id("scm-list").flex_1().min_h_0().overflow_y_scroll().track_focus(&self.scm.list_focus).children(rows).into_any_element()
+ // abstractTree.ts indent guides, from the rows' 4px modernUI inset.
+ let depths = rows.iter().map(|row| row.depth).collect();
+ let active: Vec<usize> = rows.iter().enumerate().filter(|(_, row)| row.selected).map(|(index, _)| index).collect();
+ let group = gpui::SharedString::from("scm-list");
+ let guides = self.tree_guides_in_group(group.clone(), depths, &active);
+ let inset = self.pane_row_inset();
+ let rows = rows.into_iter().enumerate().map(|(index, row)| div().relative().child(row.element).children(guides.row(index, inset)));
+ div().id("scm-list").group(group).flex_1().min_h_0().overflow_y_scroll().track_focus(&self.scm.list_focus).children(rows).into_any_element()
}
};
ViewPane { id: SCM_CHANGES_VIEW, title: "Changes".into(), description: None, actions: Some(actions.into_any_element()), draws_more: true, show_actions, body }
@@ -656,20 +670,21 @@ impl Workbench {
/// A repository's input, action button (`scm.showActionButton`) and groups; the groups show when some has
/// changes, or for the only repository without an action button.
- fn push_scm_repository_children(&self, rows: &mut Vec<gpui::AnyElement>, provider: &Provider, repository_count: usize, level: usize, window: &Window, cx: &mut Context<Self>) {
+ fn push_scm_repository_children(&self, rows: &mut Vec<ScmRow>, provider: &Provider, repository_count: usize, level: usize, window: &Window, cx: &mut Context<Self>) {
if provider.input.visible {
- rows.push(self.scm_input_row(provider, level, window, cx).into_any_element());
+ rows.push(ScmRow { depth: 1 + level, selected: false, element: self.scm_input_row(provider, level, window, cx).into_any_element() });
}
let button = provider.action_button.as_ref().filter(|button| button["command"].is_object() && self.setting("scm.showActionButton") != json!(false));
if let Some(button) = button {
- rows.push(self.scm_action_button(provider.handle, button, level, cx).into_any_element());
+ rows.push(ScmRow { depth: 1 + level, selected: false, element: self.scm_action_button(provider.handle, button, level, cx).into_any_element() });
}
let has_some_changes = provider.groups.iter().any(|group| !group.resources.is_empty());
if !has_some_changes && !(repository_count == 1 && button.is_none()) {
return;
}
for group in provider.groups.iter().filter(|group| !(group.hide_when_empty && group.resources.is_empty())) {
- rows.push(self.scm_group_row(provider, group, level, window, cx).into_any_element());
+ let selected = self.scm.selected == Some((provider.handle, group.handle, None));
+ rows.push(ScmRow { depth: 1 + level, selected, element: self.scm_group_row(provider, group, level, window, cx).into_any_element() });
if self.scm.collapsed.contains(&(provider.handle, group.handle)) {
continue;
}
@@ -678,8 +693,13 @@ impl Workbench {
let tree = self.scm_tree_mode();
for row in self.scm_rows(&root, &group.resources, &collapsed) {
rows.push(match row {
- TreeRow::Folder { path, label, depth } => self.scm_folder_row(provider, group, path, label, depth + level, window, cx).into_any_element(),
- TreeRow::Resource { index, depth } => self.scm_resource_row(provider, group, &group.resources[index], tree.then_some(depth), level, window, cx).into_any_element(),
+ TreeRow::Folder { path, label, depth } => ScmRow { depth: 2 + level + depth, selected: false, element: self.scm_folder_row(provider, group, path, label, depth + level, window, cx).into_any_element() },
+ TreeRow::Resource { index, depth } => {
+ let resource = &group.resources[index];
+ let selected = self.scm.selected == Some((provider.handle, group.handle, Some(resource.handle)));
+ let element = self.scm_resource_row(provider, group, resource, tree.then_some(depth), level, window, cx).into_any_element();
+ ScmRow { depth: 2 + level + if tree { depth } else { 0 }, selected, element }
+ }
});
}
}
diff --git a/port/ledger.md b/port/ledger.md
index c52c8eab8dc..d27c8849e45 100644
--- a/port/ledger.md
+++ b/port/ledger.md
@@ -529,7 +529,7 @@ One row per upstream unit, generated by `bun port/tools/gen-ledger.ts`; mileston
| workbench/contrib/remoteTunnel | workbench contribution | | removed | | no sign-in/AI by decision (port/notes.md); not ported |
| workbench/contrib/replNotebook | workbench contribution | M17 | verified | | verified (session m17d): cargo test -p app repl; ui-pair m17/interactive-restart.json with replPair.open repl (executed, restored, executed again, status bar) matches (/tmp/m17f); repl_notebook.rs: `$tryShowNotebookDocument` with view type `repl` (ReplEditorInput: one editor per notebook, `ensureInputBoxCell`, `REPL - N` label or `asRepl` label, scratchpad close without asking, soft revert on dispose, tab kind 4 `jupyter-notebook` editor `repl`, `debug-line-by-line` icon), the last cell as the input box under the list of the others (interactive.rs draws and runs both), `repl.execute` (insert before the input), `repl.input.focus`, `repl.focusLastItemExecuted`, `mostRecentReplEditor`, editors delta `viewType: repl`: cargo test -p app repl_notebook, ui-pair m17/interactive-window.json (replPair.open repl). The REPL editor comes back after a reload (ReplEditorSerializer `workbench.editorinputs.replEditorInput`, notebooks.rs). REPL hot exit (ReplWindowWorkingCopyEditorHandler: `notebook/<type>/repl` backups, a REPL editor opened on the restored notebook): cargo test -p app a_repl_backup_opens_a_repl_editor. Not done: the status bar while the REPL input has the focus (reference: `LF` only, then `Spaces: 4 LF Cell 1 of 1`; port: `Ln 1, Col 1 Spaces: 4 LF`), ui-pair m17/interactive-window.json (replPair.open repl) |
| workbench/contrib/sash | workbench contribution | M11 | verified | | `workbench.sash.size` (editor group sashes 4..20, their highlight 1..8; the part grid's sashes are its 4px gaps) and `workbench.sash.hoverDelay` on every sash (part grid, view panes, editor groups, find widget, keybindings table), three-dot grippers on the part sashes with `workbench.sash.autoHideGrippers` and its delay (part_grid.rs); cargo test -p app part_grid; verified: ui-pair hot-exit.json `sash` vs the reference (port/results/windows.md, milestone 11 verification) |
-| workbench/contrib/scm | workbench contribution | M14 | ported | [3 S] workbench/scm_tree.rs tree rows: the `src` folder's twistie and label sit at x 66 and 104 against the reference's 80 and 100, without its indent guides, folder decoration dot and path hover (ui-pair m11/scm-folder-menu.json `tree`, `hover`) | Resource folder menu with its resources as arguments, inline on hover (cargo test -p app a_folder_row a_folder_collects; ui-pair m11/scm-folder-menu.json `menu` with the git extension); SCM view: input box, action button, groups, resources with decorations, inline and title actions, activity badge, status bar commands (workbench/scm_view.rs); same-named repositories told apart by labels.ts `shorten` of their parent folders (quick_input.rs `shorten` with labels.test.ts's posix cases): cargo test -p app shorten_cuts same_named_repositories; quick diff gutter and peek (quick_diff.rs, quick_diff_widget.rs), multiple repositories, tree view mode and sort (scm_tree.rs), Graph view (scm_history.rs, scm_graph_view.rs) with its history item ref picker and filters (scm_graph_view/ref_picker.rs; ui-pair m11/scm-graph-refs.json), view actions (scm_actions.rs), editor commands run from the resource row: cargo test -p app scm; Graph subjects draw their `$(icon)`s (cargo test -p app a_subject_draws_its_icons); Repositories view with selection modes, sort keys, nested repositories and explorer mode's artifact groups, folders and artifacts with their menus (scm_repositories_view.rs; cargo test -p app the_repositories_ explorer_mode_), its Shift+click range and list keys (cargo test -p app the_repositories_tree_takes_shift_clicks_and_keys), Escape and `list.toggleSelection` (cargo test -p app escape_and_toggle_selection_leave_the_shown_repositories), the lone repository's expansion and `scm.repositoriesViewState` (cargo test -p app lone_repository), the shown repositories and sort key across sessions (cargo test -p app the_shown_repositories_come_back_with_their_sort_key), inline submenus with their contributed icon (cargo test -p app an_inline_submenu_opens_with_the_toolbar_arguments extension_submenus), the Repositories rows' inset, indent guides and "..." (cargo test -p app the_repositories_rows_draw_inset_guides_and_more_actions) |
+| workbench/contrib/scm | workbench contribution | M14 | ported | [3 S] workbench/scm_view.rs `scm_resource_row`: a hovered resource row shows no inline actions with the git extension (reference: Open File, Discard Changes, Stage Changes; the folder row above shows its own)<br>[3 S] workbench/scm_view.rs Changes view rows: hover and selection backgrounds span the pane, square; the reference's sit 4px in with rounded corners (modernUI padding.css, as the Repositories view's rows) | Tree mode folder rows a level in from their group, label after the twistie without folder icons, decoration dot and path hover, indent guides over the Changes rows (cargo test -p app the_changes_tree_draws_indent_guides; ui-pair m11/scm-folder-menu.json on a git copy of the fixture workspace with `scm.defaultViewMode` tree `hover`: matches the reference); row context menus without their inline group (cargo test -p app row_context_menus_leave_out_the_inline_group); Resource folder menu with its resources as arguments, inline on hover (cargo test -p app a_folder_row a_folder_collects; ui-pair m11/scm-folder-menu.json `menu` with the git extension); SCM view: input box, action button, groups, resources with decorations, inline and title actions, activity badge, status bar commands (workbench/scm_view.rs); same-named repositories told apart by labels.ts `shorten` of their parent folders (quick_input.rs `shorten` with labels.test.ts's posix cases): cargo test -p app shorten_cuts same_named_repositories; quick diff gutter and peek (quick_diff.rs, quick_diff_widget.rs), multiple repositories, tree view mode and sort (scm_tree.rs), Graph view (scm_history.rs, scm_graph_view.rs) with its history item ref picker and filters (scm_graph_view/ref_picker.rs; ui-pair m11/scm-graph-refs.json), view actions (scm_actions.rs), editor commands run from the resource row: cargo test -p app scm; Graph subjects draw their `$(icon)`s (cargo test -p app a_subject_draws_its_icons); Repositories view with selection modes, sort keys, nested repositories and explorer mode's artifact groups, folders and artifacts with their menus (scm_repositories_view.rs; cargo test -p app the_repositories_ explorer_mode_), its Shift+click range and list keys (cargo test -p app the_repositories_tree_takes_shift_clicks_and_keys), Escape and `list.toggleSelection` (cargo test -p app escape_and_toggle_selection_leave_the_shown_repositories), the lone repository's expansion and `scm.repositoriesViewState` (cargo test -p app lone_repository), the shown repositories and sort key across sessions (cargo test -p app the_shown_repositories_come_back_with_their_sort_key), inline submenus with their contributed icon (cargo test -p app an_inline_submenu_opens_with_the_toolbar_arguments extension_submenus), the Repositories rows' inset, indent guides and "..." (cargo test -p app the_repositories_rows_draw_inset_guides_and_more_actions) |
| workbench/contrib/screenshotTool | workbench contribution | | removed | | Artur: internal infrastructure or developer tool with no 1:1 counterpart in the native port |
| workbench/contrib/scrollLocking | workbench contribution | M14 | verified | | workbench/scroll_locking.rs: Toggle and Hold Locked Scrolling and the prominent `status.scrollLockingEnabled` entry: cargo test -p app scroll_locking; a locked wheel scroll moves every other visible editor as far from its position when tracked (`onDidEditorPaneScroll`; cargo test -p app a_locked_scroll_moves_every_other_visible_editor); Hold locks while its key is down and unlocks on the key up (keybindingService.ts `enableKeybindingHoldMode`; cargo test -p app a_held_key_locks_scrolling_until_it_goes_up); without a focused element Hold toggles, as the key up reaches the workbench through the focus path |
| workbench/contrib/search | workbench contribution | M12 | verified | | Search view (workbench/search_view.rs, search_actions.rs) and its model (search_model.rs): cargo test -p app search_model (searchResult, fileMatch and replace tests) and workbench::search_actions (context menu, input history, hover right click, the replace preview opened and updated with the replace string), port/tools/ui-pair frames match the reference in dark, light and hc (port/notes.md milestone 12); anythingQuickAccess.ts file picks: cargo test -p app anything_quick_access quick_open. No notebook or AI results; Find in Folder from the Explorer (cargo test -p app find_in_folder; ui-pair m12/find-in-folder.json with `search.mode` newEditor matches); ui-pair m12/search-replace.json (query, Replace input, preview) matches; the message words at their exact widths, so "2 results in 2 files - Open in editor" fits one line as in the reference (cargo test -p app the_message_words_take_their_exact_width; pair: same box, 408 device px wide) |