fix: rich text link handling
This commit is contained in:
@@ -229,18 +229,30 @@ impl MarkdownText {
|
|||||||
|
|
||||||
let (description, src) =
|
let (description, src) =
|
||||||
if cursor.node().kind_id() == MARKDOWN_KIND_ID_LINK_DESTINATION {
|
if cursor.node().kind_id() == MARKDOWN_KIND_ID_LINK_DESTINATION {
|
||||||
let node = cursor.node();
|
let src = cursor
|
||||||
let src = &content[node_range!()];
|
.node()
|
||||||
|
.utf8_text(content.as_ref())
|
||||||
|
.ok()
|
||||||
|
.unwrap_or_default();
|
||||||
(src, src)
|
(src, src)
|
||||||
} else {
|
} else {
|
||||||
let node = cursor.node();
|
let description = cursor
|
||||||
let description = &content[node_range!()];
|
.node()
|
||||||
|
.utf8_text(content.as_ref())
|
||||||
|
.ok()
|
||||||
|
.unwrap_or_default();
|
||||||
if cursor.goto_next_sibling() {
|
if cursor.goto_next_sibling() {
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
cursor.node().kind_id() == MARKDOWN_KIND_ID_LINK_DESTINATION
|
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 {
|
} else {
|
||||||
// no src for this link node
|
// no src for this link node
|
||||||
(description, "")
|
(description, "")
|
||||||
@@ -658,7 +670,11 @@ impl gpui::Render for MarkdownText {
|
|||||||
content,
|
content,
|
||||||
has_padding,
|
has_padding,
|
||||||
} => match decoration {
|
} => 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()
|
| Some(decoration) => div()
|
||||||
.w_full()
|
.w_full()
|
||||||
.flex()
|
.flex()
|
||||||
|
|||||||
@@ -49,7 +49,8 @@ enum RichTextElement {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
enum RichTextClickTarget {
|
#[derive(Debug)]
|
||||||
|
pub(crate) enum RichTextClickTarget {
|
||||||
Link(gpui::SharedString),
|
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 {
|
impl gpui::RenderOnce for RichText {
|
||||||
fn render(self, _window: &mut gpui::Window, cx: &mut gpui::App) -> impl gpui::IntoElement {
|
fn render(self, _window: &mut gpui::Window, cx: &mut gpui::App) -> impl gpui::IntoElement {
|
||||||
let theme = app::current_theme(cx);
|
let theme = app::current_theme(cx);
|
||||||
|
|||||||
Reference in New Issue
Block a user