Fix review comments
This commit is contained in:
parent
9db3f54ac3
commit
e606e2e239
3 changed files with 13 additions and 31 deletions
|
@ -1,6 +1,6 @@
|
||||||
use gpui::DefiniteLength;
|
|
||||||
use gpui::{
|
use gpui::{
|
||||||
FontStyle, FontWeight, HighlightStyle, SharedString, StrikethroughStyle, UnderlineStyle, px,
|
DefiniteLength, FontStyle, FontWeight, HighlightStyle, SharedString, StrikethroughStyle,
|
||||||
|
UnderlineStyle, px,
|
||||||
};
|
};
|
||||||
use language::HighlightId;
|
use language::HighlightId;
|
||||||
use std::{fmt::Display, ops::Range, path::PathBuf};
|
use std::{fmt::Display, ops::Range, path::PathBuf};
|
||||||
|
|
|
@ -938,7 +938,6 @@ mod tests {
|
||||||
HighlightId, Language, LanguageConfig, LanguageMatcher, LanguageRegistry, tree_sitter_rust,
|
HighlightId, Language, LanguageConfig, LanguageMatcher, LanguageRegistry, tree_sitter_rust,
|
||||||
};
|
};
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
use ui::Pixels;
|
|
||||||
|
|
||||||
async fn parse(input: &str) -> ParsedMarkdown {
|
async fn parse(input: &str) -> ParsedMarkdown {
|
||||||
parse_markdown(input, None, None).await
|
parse_markdown(input, None, None).await
|
||||||
|
@ -1226,35 +1225,25 @@ mod tests {
|
||||||
// Test pixel values
|
// Test pixel values
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
MarkdownParser::parse_length("100px"),
|
MarkdownParser::parse_length("100px"),
|
||||||
Some(DefiniteLength::Absolute(AbsoluteLength::Pixels(Pixels(
|
Some(DefiniteLength::Absolute(AbsoluteLength::Pixels(px(100.0))))
|
||||||
100.0
|
|
||||||
))))
|
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
MarkdownParser::parse_length("50px"),
|
MarkdownParser::parse_length("50px"),
|
||||||
Some(DefiniteLength::Absolute(AbsoluteLength::Pixels(Pixels(
|
Some(DefiniteLength::Absolute(AbsoluteLength::Pixels(px(50.0))))
|
||||||
50.0
|
|
||||||
))))
|
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
MarkdownParser::parse_length("0px"),
|
MarkdownParser::parse_length("0px"),
|
||||||
Some(DefiniteLength::Absolute(AbsoluteLength::Pixels(Pixels(
|
Some(DefiniteLength::Absolute(AbsoluteLength::Pixels(px(0.0))))
|
||||||
0.0
|
|
||||||
))))
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Test values without units (should be treated as pixels)
|
// Test values without units (should be treated as pixels)
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
MarkdownParser::parse_length("100"),
|
MarkdownParser::parse_length("100"),
|
||||||
Some(DefiniteLength::Absolute(AbsoluteLength::Pixels(Pixels(
|
Some(DefiniteLength::Absolute(AbsoluteLength::Pixels(px(100.0))))
|
||||||
100.0
|
|
||||||
))))
|
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
MarkdownParser::parse_length("42"),
|
MarkdownParser::parse_length("42"),
|
||||||
Some(DefiniteLength::Absolute(AbsoluteLength::Pixels(Pixels(
|
Some(DefiniteLength::Absolute(AbsoluteLength::Pixels(px(42.0))))
|
||||||
42.0
|
|
||||||
))))
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Test invalid values
|
// Test invalid values
|
||||||
|
@ -1272,15 +1261,11 @@ mod tests {
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
MarkdownParser::parse_length("100.25px"),
|
MarkdownParser::parse_length("100.25px"),
|
||||||
Some(DefiniteLength::Absolute(AbsoluteLength::Pixels(Pixels(
|
Some(DefiniteLength::Absolute(AbsoluteLength::Pixels(px(100.25))))
|
||||||
100.25
|
|
||||||
))))
|
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
MarkdownParser::parse_length("42.0"),
|
MarkdownParser::parse_length("42.0"),
|
||||||
Some(DefiniteLength::Absolute(AbsoluteLength::Pixels(Pixels(
|
Some(DefiniteLength::Absolute(AbsoluteLength::Pixels(px(42.0))))
|
||||||
42.0
|
|
||||||
))))
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,9 +26,6 @@ use ui::{
|
||||||
};
|
};
|
||||||
use workspace::{OpenOptions, OpenVisible, Workspace};
|
use workspace::{OpenOptions, OpenVisible, Workspace};
|
||||||
|
|
||||||
const OPEN_IMAGE_TOOLTIP: SharedString = SharedString::new_static("open image");
|
|
||||||
const TOGGLE_CHECKBOX_TOOLTIP: SharedString = SharedString::new_static("toggle checkbox");
|
|
||||||
|
|
||||||
pub struct CheckboxClickedEvent {
|
pub struct CheckboxClickedEvent {
|
||||||
pub checked: bool,
|
pub checked: bool,
|
||||||
pub source_range: Range<usize>,
|
pub source_range: Range<usize>,
|
||||||
|
@ -263,7 +260,7 @@ fn render_markdown_list_item(
|
||||||
)
|
)
|
||||||
.hover(|s| s.cursor_pointer())
|
.hover(|s| s.cursor_pointer())
|
||||||
.tooltip(|_, cx| {
|
.tooltip(|_, cx| {
|
||||||
InteractiveMarkdownElementTooltip::new(None, TOGGLE_CHECKBOX_TOOLTIP, cx).into()
|
InteractiveMarkdownElementTooltip::new(None, "toggle checkbox", cx).into()
|
||||||
})
|
})
|
||||||
.into_any_element(),
|
.into_any_element(),
|
||||||
};
|
};
|
||||||
|
@ -767,7 +764,7 @@ fn render_markdown_image(image: &Image, cx: &mut RenderContext) -> AnyElement {
|
||||||
move |_, cx| {
|
move |_, cx| {
|
||||||
InteractiveMarkdownElementTooltip::new(
|
InteractiveMarkdownElementTooltip::new(
|
||||||
Some(alt_text.clone().unwrap_or(link.to_string().into())),
|
Some(alt_text.clone().unwrap_or(link.to_string().into())),
|
||||||
OPEN_IMAGE_TOOLTIP,
|
"open image",
|
||||||
cx,
|
cx,
|
||||||
)
|
)
|
||||||
.into()
|
.into()
|
||||||
|
@ -811,14 +808,14 @@ struct InteractiveMarkdownElementTooltip {
|
||||||
impl InteractiveMarkdownElementTooltip {
|
impl InteractiveMarkdownElementTooltip {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
tooltip_text: Option<SharedString>,
|
tooltip_text: Option<SharedString>,
|
||||||
action_text: SharedString,
|
action_text: impl Into<SharedString>,
|
||||||
cx: &mut App,
|
cx: &mut App,
|
||||||
) -> Entity<Self> {
|
) -> Entity<Self> {
|
||||||
let tooltip_text = tooltip_text.map(|t| util::truncate_and_trailoff(&t, 50).into());
|
let tooltip_text = tooltip_text.map(|t| util::truncate_and_trailoff(&t, 50).into());
|
||||||
|
|
||||||
cx.new(|_cx| Self {
|
cx.new(|_cx| Self {
|
||||||
tooltip_text,
|
tooltip_text,
|
||||||
action_text,
|
action_text: action_text.into(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue