fix: rich text link handling
This commit is contained in:
@@ -229,18 +229,30 @@ impl MarkdownText {
|
||||
|
||||
let (description, src) =
|
||||
if cursor.node().kind_id() == MARKDOWN_KIND_ID_LINK_DESTINATION {
|
||||
let node = cursor.node();
|
||||
let src = &content[node_range!()];
|
||||
let src = cursor
|
||||
.node()
|
||||
.utf8_text(content.as_ref())
|
||||
.ok()
|
||||
.unwrap_or_default();
|
||||
(src, src)
|
||||
} else {
|
||||
let node = cursor.node();
|
||||
let description = &content[node_range!()];
|
||||
let description = cursor
|
||||
.node()
|
||||
.utf8_text(content.as_ref())
|
||||
.ok()
|
||||
.unwrap_or_default();
|
||||
if cursor.goto_next_sibling() {
|
||||
debug_assert!(
|
||||
cursor.node().kind_id() == MARKDOWN_KIND_ID_LINK_DESTINATION
|
||||
);
|
||||
let node = cursor.node();
|
||||
(description, &content[node_range!()])
|
||||
(
|
||||
description,
|
||||
cursor
|
||||
.node()
|
||||
.utf8_text(content.as_ref())
|
||||
.ok()
|
||||
.unwrap_or_default(),
|
||||
)
|
||||
} else {
|
||||
// no src for this link node
|
||||
(description, "")
|
||||
@@ -658,7 +670,11 @@ impl gpui::Render for MarkdownText {
|
||||
content,
|
||||
has_padding,
|
||||
} => match decoration {
|
||||
| None => div().min_w_0().child(rich_text(content.clone())),
|
||||
| None => div()
|
||||
.min_w_0()
|
||||
.child(rich_text(content.clone()).on_click(|asd, _, _| {
|
||||
println!("link clicked {:?}", asd);
|
||||
})),
|
||||
| Some(decoration) => div()
|
||||
.w_full()
|
||||
.flex()
|
||||
|
||||
@@ -49,7 +49,8 @@ enum RichTextElement {
|
||||
},
|
||||
}
|
||||
|
||||
enum RichTextClickTarget {
|
||||
#[derive(Debug)]
|
||||
pub(crate) enum RichTextClickTarget {
|
||||
Link(gpui::SharedString),
|
||||
}
|
||||
|
||||
@@ -158,6 +159,16 @@ impl RichTextContentBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
impl RichText {
|
||||
pub(crate) fn on_click(
|
||||
mut self,
|
||||
f: impl Fn(&RichTextClickTarget, &mut gpui::Window, &mut gpui::App) + 'static,
|
||||
) -> Self {
|
||||
self.on_click = Some(Rc::from(f));
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl gpui::RenderOnce for RichText {
|
||||
fn render(self, _window: &mut gpui::Window, cx: &mut gpui::App) -> impl gpui::IntoElement {
|
||||
let theme = app::current_theme(cx);
|
||||
|
||||
Reference in New Issue
Block a user