Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

ui: Fix modifier key hints on macOS (#63807)

IlYoung5bdfa7c8ab7c
diff --git a/crates/edit_prediction_ui/src/edit_prediction_button.rs b/crates/edit_prediction_ui/src/edit_prediction_button.rs
index 0a90a90b763..bd029b0a21e 100644
--- a/crates/edit_prediction_ui/src/edit_prediction_button.rs
+++ b/crates/edit_prediction_ui/src/edit_prediction_button.rs
@@ -822,7 +822,12 @@ impl EditPredictionButton {
ContextMenuEntry::new("Subtle")
.toggleable(IconPosition::Start, subtle_mode)
.documentation_aside(DocumentationSide::Left, move |_| {
- Label::new("Display predictions inline only when holding a modifier key (alt by default).").into_any_element()
+ Label::new(concat!(
+ "Display predictions inline only when holding a modifier key (",
+ ui::alt_key_name!(),
+ " by default)."
+ ))
+ .into_any_element()
})
.handler({
let fs = fs.clone();
diff --git a/crates/git_ui/src/branch_picker.rs b/crates/git_ui/src/branch_picker.rs
index d9272e5fdf9..a7989c422c5 100644
--- a/crates/git_ui/src/branch_picker.rs
+++ b/crates/git_ui/src/branch_picker.rs
@@ -883,7 +883,7 @@ impl Render for DeleteBranchTooltip {
Tooltip::with_meta_in(
"Delete Branch",
Some(&branch_picker::DeleteBranch),
- "Hold alt to force delete",
+ concat!("Hold ", ui::alt_key_name!(), " to force delete"),
&self.focus_handle,
cx,
)
diff --git a/crates/git_ui_core/src/worktree_picker.rs b/crates/git_ui_core/src/worktree_picker.rs
index 5a4b278bbce..d518bee6268 100644
--- a/crates/git_ui_core/src/worktree_picker.rs
+++ b/crates/git_ui_core/src/worktree_picker.rs
@@ -413,7 +413,7 @@ impl Render for DeleteWorktreeTooltip {
Tooltip::with_meta_in(
"Delete Worktree",
Some(&DeleteWorktree),
- "Hold alt to force delete",
+ concat!("Hold ", ui::alt_key_name!(), " to force delete"),
&self.focus_handle,
cx,
)
diff --git a/crates/keymap_editor/src/keymap_editor.rs b/crates/keymap_editor/src/keymap_editor.rs
index 7ce17401158..bc27d0b13b7 100644
--- a/crates/keymap_editor/src/keymap_editor.rs
+++ b/crates/keymap_editor/src/keymap_editor.rs
@@ -1163,7 +1163,7 @@ impl KeymapEditor {
Tooltip::with_meta(
"View conflicts",
Some(&ToggleConflictFilter),
- "Use alt+click to show all conflicts",
+ concat!("Use ", ui::alt_key_name!(), "+click to show all conflicts"),
cx,
)
})
@@ -1193,11 +1193,15 @@ impl KeymapEditor {
}))
} else {
base_button_style(index, IconName::Info)
- .tooltip(|_window, cx| {
+ .tooltip(|_window, cx| {
Tooltip::with_meta(
"Show matching keybinds",
Some(&ShowMatchingKeybinds),
- "This binding is overridden by other bindings.\nUse alt+click to edit this binding",
+ concat!(
+ "This binding is overridden by other bindings.\nUse ",
+ ui::alt_key_name!(),
+ "+click to edit this binding"
+ ),
cx,
)
})
diff --git a/crates/ui/src/styles/platform.rs b/crates/ui/src/styles/platform.rs
index 0d873a2ff2c..cee7dfe0135 100644
--- a/crates/ui/src/styles/platform.rs
+++ b/crates/ui/src/styles/platform.rs
@@ -1,3 +1,21 @@
+/// Expands to a literal so platform-specific hints can use `concat!` without allocating.
+#[cfg(target_os = "macos")]
+#[macro_export]
+macro_rules! alt_key_name {
+ () => {
+ "option"
+ };
+}
+
+/// Expands to a literal so platform-specific hints can use `concat!` without allocating.
+#[cfg(not(target_os = "macos"))]
+#[macro_export]
+macro_rules! alt_key_name {
+ () => {
+ "alt"
+ };
+}
+
/// The platform style to use when rendering UI.
///
/// This can be used to abstract over platform differences.