From 3620139700b1f6e9249b5fa1c69425645887608c Mon Sep 17 00:00:00 2001 From: Kislay Verma Date: Wed, 24 Jul 2024 20:51:44 +0530 Subject: [PATCH] copy_and_paste: Paste text first unformatted and then formatted. This commit makes pasting formatted text a two-step process: - Insert unformatted text - Insert formatting This way, undo (Ctrl+Z) will restore the original pre-formatting syntax. This is the same as the approach taken with auto-formatting in #29302. Fixes #31061 --- web/src/copy_and_paste.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/web/src/copy_and_paste.ts b/web/src/copy_and_paste.ts index 59c2d9fdee..c88f56eb87 100644 --- a/web/src/copy_and_paste.ts +++ b/web/src/copy_and_paste.ts @@ -745,6 +745,11 @@ export function paste_handler(this: HTMLTextAreaElement, event: JQuery.Triggered event.stopPropagation(); paste_html = maybe_transform_html(paste_html, paste_text); const text = paste_handler_converter(paste_html); + // Pasting formatted text is a two-step process: + // First we paste unformatted text, + // then overwrite it with formatted text. + // This way, undo restores the pre-formatting syntax. + add_text_and_select(trimmed_paste_text, $textarea); compose_ui.insert_and_scroll_into_view(text, $textarea); } }