ui: Add functions for generating textual representations of key bindings (#15287)

This PR adds some helper functions in the `ui` crate that can be used to
get textural representations of keystrokes or key bindings.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-07-26 12:52:59 -04:00 committed by GitHub
parent a5279cc48a
commit c937a2fcdd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 206 additions and 23 deletions

View file

@ -1,8 +1,8 @@
use gpui::{AnyElement, WeakView};
use gpui::{AnyElement, Modifiers, WeakView};
use markdown_preview::{
markdown_preview_view::MarkdownPreviewView, OpenPreview, OpenPreviewToTheSide,
};
use ui::{prelude::*, IconButtonShape, Tooltip};
use ui::{prelude::*, text_for_keystroke, IconButtonShape, Tooltip};
use workspace::Workspace;
use crate::QuickActionBar;
@ -27,9 +27,10 @@ impl QuickActionBar {
return None;
}
let tooltip_meta = match self.platform_style {
PlatformStyle::Mac => "Option+Click to open in a split",
_ => "Alt+Click to open in a split",
let alt_click = gpui::Keystroke {
key: "click".into(),
modifiers: Modifiers::alt(),
..Default::default()
};
let button = IconButton::new("toggle-markdown-preview", IconName::Eye)
@ -40,7 +41,10 @@ impl QuickActionBar {
Tooltip::with_meta(
"Preview Markdown",
Some(&markdown_preview::OpenPreview),
tooltip_meta,
format!(
"{} to open in a split",
text_for_keystroke(&alt_click, PlatformStyle::platform())
),
cx,
)
})