Skip to content

Visual Studio Code, rebuilt in Rust

Rust

fix(titlebar): draw disabled Go Back and Forward in disabledForeground

rokarturba350e76ec84
diff --git a/native/crates/app/src/workbench.rs b/native/crates/app/src/workbench.rs
index 14d553537d9..d8bfc5f02c7 100644
--- a/native/crates/app/src/workbench.rs
+++ b/native/crates/app/src/workbench.rs
@@ -1314,10 +1314,9 @@ impl Workbench {
}
/// The command center's Go Back and Go Forward (`MenuId.CommandCenter` orders 1 and 2): enabled by their
- /// `canNavigateBack`/`canNavigateForward` precondition, pointer only then (actionbar.css `.disabled`). modernUI
- /// commandCenter.css keeps both states in `commandCenter.foreground`.
+ /// `canNavigateBack`/`canNavigateForward` precondition, pointer only then (actionbar.css `.disabled`).
fn navigation_button(&self, icon: &'static str, title: &'static str, command: &'static str, enabled: bool, cx: &mut Context<Self>) -> Stateful<Div> {
- self.icon(icon, 22., 16., self.color("commandCenter.foreground"))
+ self.icon(icon, 22., 16., self.navigation_icon_color(enabled))
.id(command)
.rounded(px(4.))
.when(enabled, |button| {
@@ -1329,6 +1328,12 @@ impl Workbench {
.child(self.action_hover(title, command, HoverOptions::instant()))
}
+ /// The codicon is the label's `::before`: modernUI commandCenter.css colors the label in
+ /// `commandCenter.foreground`, but actionbar.css's `.disabled .action-label:not(.icon)::before` wins on the glyph.
+ fn navigation_icon_color(&self, enabled: bool) -> Rgba {
+ self.color(if enabled { "commandCenter.foreground" } else { "disabledForeground" })
+ }
+
/// The window's title bar; an editor window's has its compact mode and always on top toggles in place of the
/// layout controls, and its border. A compact one has no command center and shows the editor actions.
/// NativeTitlebarPart.minimumHeight: DEFAULT_CUSTOM_TITLEBAR_HEIGHT with the command center, else macTitlebarSize.
diff --git a/native/crates/app/src/workbench/title_bar_actions/tests.rs b/native/crates/app/src/workbench/title_bar_actions/tests.rs
index b91d195d7bd..5f5ff9335af 100644
--- a/native/crates/app/src/workbench/title_bar_actions/tests.rs
+++ b/native/crates/app/src/workbench/title_bar_actions/tests.rs
@@ -155,6 +155,23 @@ fn the_command_center_label_is_a_22px_line(cx: &mut TestAppContext) {
assert_eq!(label.size.height, px(22.));
}
+/// A new window has no history: Go Back draws its glyph in `disabledForeground` (actionbar.css `::before`), as the
+/// reference's pixel-check frames show, over modernUI commandCenter.css's label color.
+#[gpui::test]
+fn go_back_without_history_draws_in_the_disabled_foreground(cx: &mut TestAppContext) {
+ let app_root = Path::new(env!("VSCODE_SRC")).to_path_buf();
+ let themes = scan_extension(&app_root.join("extensions/theme-defaults"), true).unwrap();
+ let theme = load_theme(&[themes], "Dark Modern").unwrap();
+ let settings = Arc::new(Mutex::new(Settings::load(Registry::with_extensions(&[]), std::env::temp_dir().join("code-gpui-title-bar-go-back/User"), None)));
+ let (workbench, cx) = cx.add_window_view(|_, cx| Workbench::new(theme, app_root.clone(), None, Languages::new(&[]), settings, HostSync::new(std::sync::mpsc::channel().0), cx));
+ cx.run_until_parked();
+ workbench.read_with(cx, |workbench, _| {
+ assert!(!workbench.can_navigate(true));
+ assert_eq!(workbench.navigation_icon_color(false), workbench.color("disabledForeground"));
+ assert_eq!(workbench.navigation_icon_color(true), workbench.color("commandCenter.foreground"));
+ });
+}
+
/// titlebarPart.ts `createActionToolBarMenus`: `MenuId.TitleBar`'s `0_leading` group leads the toolbar, its
/// `navigation` group follows the layout controls, sorted with the bell (order 10000), and its other groups go to the
/// overflow.