From a62ee3f8e07f92096403536aaa25ec3da485cf46 Mon Sep 17 00:00:00 2001 From: Kislay Verma Date: Fri, 6 Jun 2025 22:23:37 +0530 Subject: [PATCH] compose_paste: Don't paste formatted text at md link marker. This prevents the case when we have text like `[abcd](url)` in the compose box and the "url" part is selected, and we paste a link copied from message actions popover. --- web/src/compose_paste.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/web/src/compose_paste.ts b/web/src/compose_paste.ts index 38ea02c5d7..366515c1e5 100644 --- a/web/src/compose_paste.ts +++ b/web/src/compose_paste.ts @@ -628,6 +628,13 @@ export function paste_handler(this: HTMLTextAreaElement, event: JQuery.Triggered // Only intervene to generate formatted links when dealing // with a URL and a URL-safe range selection. if (isUrl(trimmed_paste_text)) { + if (cursor_at_markdown_link_marker($textarea)) { + // When pasting a link after the link marker syntax, we want to + // avoid inserting markdown syntax text and instead just paste + // the raw text, possibly replacing any selection. In other words, + // let the browser handle it. + return; + } if (is_safe_url_paste_target($textarea)) { event.preventDefault(); event.stopPropagation(); @@ -635,12 +642,7 @@ export function paste_handler(this: HTMLTextAreaElement, event: JQuery.Triggered compose_ui.format_text($textarea, "linked", url); return; } - - if ( - !compose_ui.cursor_inside_code_block($textarea) && - !cursor_at_markdown_link_marker($textarea) && - !compose_ui.shift_pressed - ) { + if (!compose_ui.cursor_inside_code_block($textarea) && !compose_ui.shift_pressed) { // Try to transform the url to #**stream>topic** syntax // if it is a valid url. const syntax_text = try_stream_topic_syntax_text(trimmed_paste_text);