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
This commit is contained in:
Kislay Verma 2024-07-24 20:51:44 +05:30 committed by Tim Abbott
parent e6c0e096f9
commit 3620139700
1 changed files with 5 additions and 0 deletions

View File

@ -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);
}
}