mirror of
https://github.com/zed-industries/zed.git
synced 2026-05-31 19:05:00 +07:00
Avoid linkifying non-interactive code spans (#57515)
## Summary - Skip code-span link resolution when markdown prevents mouse interaction - Add regression coverage for non-interactive code spans ## Tests - cargo test -p markdown test_code_span_link_ignores_code_when_mouse_interaction_is_prevented Release Notes: - Fixed extra link styling on file paths in agent tool call labels.
This commit is contained in:
parent
d3e27abc87
commit
2c26e5e544
1 changed files with 43 additions and 3 deletions
|
|
@ -1213,7 +1213,10 @@ impl MarkdownElement {
|
|||
range: Range<usize>,
|
||||
cx: &App,
|
||||
) {
|
||||
let link_url = if builder.code_block_stack.is_empty() && builder.link_depth == 0 {
|
||||
let link_url = if builder.code_block_stack.is_empty()
|
||||
&& builder.link_depth == 0
|
||||
&& !self.style.prevent_mouse_interaction
|
||||
{
|
||||
self.code_span_link
|
||||
.as_ref()
|
||||
.and_then(|callback| callback(text, cx))
|
||||
|
|
@ -3490,7 +3493,10 @@ mod tests {
|
|||
use super::*;
|
||||
use gpui::{TestAppContext, size};
|
||||
use language::{Language, LanguageConfig, LanguageMatcher};
|
||||
use std::sync::Arc;
|
||||
use std::sync::{
|
||||
Arc,
|
||||
atomic::{AtomicUsize, Ordering},
|
||||
};
|
||||
|
||||
fn ensure_theme_initialized(cx: &mut TestAppContext) {
|
||||
cx.update(|cx| {
|
||||
|
|
@ -3562,6 +3568,15 @@ mod tests {
|
|||
markdown: &str,
|
||||
callback: impl Fn(&str, &App) -> Option<SharedString> + 'static,
|
||||
cx: &mut TestAppContext,
|
||||
) -> RenderedText {
|
||||
render_markdown_with_code_span_link_style(markdown, MarkdownStyle::default(), callback, cx)
|
||||
}
|
||||
|
||||
fn render_markdown_with_code_span_link_style(
|
||||
markdown: &str,
|
||||
style: MarkdownStyle,
|
||||
callback: impl Fn(&str, &App) -> Option<SharedString> + 'static,
|
||||
cx: &mut TestAppContext,
|
||||
) -> RenderedText {
|
||||
struct TestWindow;
|
||||
|
||||
|
|
@ -3580,7 +3595,7 @@ mod tests {
|
|||
Default::default(),
|
||||
size(px(600.0), px(600.0)),
|
||||
|_window, _cx| {
|
||||
MarkdownElement::new(markdown, MarkdownStyle::default())
|
||||
MarkdownElement::new(markdown, style)
|
||||
.on_code_span_link(callback)
|
||||
.code_block_renderer(CodeBlockRenderer::Default {
|
||||
copy_button_visibility: CopyButtonVisibility::Hidden,
|
||||
|
|
@ -4251,6 +4266,31 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_code_span_link_ignores_code_when_mouse_interaction_is_prevented(
|
||||
cx: &mut TestAppContext,
|
||||
) {
|
||||
let callback_count = Arc::new(AtomicUsize::new(0));
|
||||
let rendered = render_markdown_with_code_span_link_style(
|
||||
"see `foo.rs` for details",
|
||||
MarkdownStyle {
|
||||
prevent_mouse_interaction: true,
|
||||
..MarkdownStyle::default()
|
||||
},
|
||||
{
|
||||
let callback_count = callback_count.clone();
|
||||
move |text, _cx| {
|
||||
callback_count.fetch_add(1, Ordering::Relaxed);
|
||||
(text == "foo.rs").then(|| "file:///tmp/foo.rs".into())
|
||||
}
|
||||
},
|
||||
cx,
|
||||
);
|
||||
|
||||
assert!(rendered.links.is_empty());
|
||||
assert_eq!(callback_count.load(Ordering::Relaxed), 0);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_code_span_link_ignores_code_without_callback(cx: &mut TestAppContext) {
|
||||
let rendered = render_markdown("see `foo.rs` for details", cx);
|
||||
|
|
|
|||
Loading…
Reference in a new issue