markdown: Don't retain MarkdownStyle in favor of using MarkdownElement directly (#28255)

This PR removes the retained `MarkdownStyle` on the `Markdown` entity in
favor of using the `MarkdownElement` directly and passing the
`MarkdownStyle` to it.

This makes it so switching themes will be reflected live in the code
block styles.

Release Notes:

- N/A

---------

Co-authored-by: Antonio Scandurra <me@as-cii.com>
Co-authored-by: Agus Zubiaga <hi@aguz.me>
This commit is contained in:
Marshall Bowers 2025-04-07 15:03:24 -04:00 committed by GitHub
parent aa026156f2
commit b6ee367ee0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 370 additions and 374 deletions

View file

@ -95,14 +95,13 @@ impl BlameRenderer for GitBlameRenderer {
)
}
})
.hoverable_tooltip(move |window, cx| {
.hoverable_tooltip(move |_window, cx| {
cx.new(|cx| {
CommitTooltip::blame_entry(
&blame_entry,
details.clone(),
repository.clone(),
workspace.clone(),
window,
cx,
)
})
@ -145,14 +144,13 @@ impl BlameRenderer for GitBlameRenderer {
.child(Icon::new(IconName::FileGit).color(Color::Hint))
.child(text)
.gap_2()
.hoverable_tooltip(move |window, cx| {
.hoverable_tooltip(move |_window, cx| {
let tooltip = cx.new(|cx| {
CommitTooltip::blame_entry(
&blame_entry,
details.clone(),
repository.clone(),
workspace.clone(),
window,
cx,
)
});

View file

@ -8,7 +8,7 @@ use gpui::{
App, Asset, ClipboardItem, Element, Entity, MouseButton, ParentElement, Render, ScrollHandle,
StatefulInteractiveElement, WeakEntity, prelude::*,
};
use markdown::Markdown;
use markdown::{Markdown, MarkdownElement};
use project::git_store::Repository;
use settings::Settings;
use std::hash::Hash;
@ -118,7 +118,6 @@ impl CommitTooltip {
details: Option<ParsedCommitMessage>,
repository: Entity<Repository>,
workspace: WeakEntity<Workspace>,
window: &mut Window,
cx: &mut Context<Self>,
) -> Self {
let commit_time = blame
@ -140,7 +139,6 @@ impl CommitTooltip {
},
repository,
workspace,
window,
cx,
)
}
@ -149,13 +147,8 @@ impl CommitTooltip {
commit: CommitDetails,
repository: Entity<Repository>,
workspace: WeakEntity<Workspace>,
window: &mut Window,
cx: &mut Context<Self>,
) -> Self {
let mut style = hover_markdown_style(window, cx);
if let Some(code_block) = &style.code_block.text {
style.base_text_style.refine(code_block);
}
let markdown = cx.new(|cx| {
Markdown::new(
commit
@ -163,7 +156,6 @@ impl CommitTooltip {
.as_ref()
.map(|message| message.message.clone())
.unwrap_or_default(),
style,
None,
None,
cx,
@ -199,12 +191,19 @@ impl Render for CommitTooltip {
OffsetDateTime::now_utc(),
time_format::TimestampFormat::MediumAbsolute,
);
let markdown_style = {
let mut style = hover_markdown_style(window, cx);
if let Some(code_block) = &style.code_block.text {
style.base_text_style.refine(code_block);
}
style
};
let message = self
.commit
.message
.as_ref()
.map(|_| self.markdown.clone().into_any_element())
.map(|_| MarkdownElement::new(self.markdown.clone(), markdown_style).into_any())
.unwrap_or("<no commit message>".into_any());
let pull_request = self

View file

@ -3927,9 +3927,9 @@ impl GitPanelMessageTooltip {
}),
};
this.update_in(cx, |this: &mut GitPanelMessageTooltip, window, cx| {
this.update(cx, |this: &mut GitPanelMessageTooltip, cx| {
this.commit_tooltip = Some(cx.new(move |cx| {
CommitTooltip::new(commit_details, repository, workspace, window, cx)
CommitTooltip::new(commit_details, repository, workspace, cx)
}));
cx.notify();
})