Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

compose_paste: Extract actual pasting code into a function.

Kislay Vermaddce29ac50f8
diff --git a/web/src/compose_paste.ts b/web/src/compose_paste.ts
index 8b7168c530b..fc281cb1a04 100644
--- a/web/src/compose_paste.ts
+++ b/web/src/compose_paste.ts
@@ -645,6 +645,24 @@ function create_text_file(text: string, filename: string): File {
return new File([blob], filename, {type: "text/plain"});
}
+function do_paste_text(
+ paste_html: string,
+ paste_text: string,
+ $textarea: JQuery<HTMLTextAreaElement>,
+): void {
+ paste_html = maybe_transform_html(paste_html, paste_text);
+ const text = paste_handler_converter(paste_html, $textarea);
+ const trimmed_paste_text = paste_text.trim();
+ if (trimmed_paste_text !== text) {
+ // Pasting formatted text is a two-step process: First
+ // we paste unformatted text, then overwrite it with
+ // formatted text, so that undo restores the
+ // pre-formatting syntax.
+ add_text_and_select(trimmed_paste_text, $textarea);
+ }
+ compose_ui.insert_and_scroll_into_view(text, $textarea);
+}
+
export function paste_handler(
this: HTMLTextAreaElement,
event: JQuery.TriggeredEvent,
@@ -746,16 +764,7 @@ export function paste_handler(
}
event.preventDefault();
event.stopPropagation();
- paste_html = maybe_transform_html(paste_html, paste_text);
- const text = paste_handler_converter(paste_html, $textarea);
- if (trimmed_paste_text !== text) {
- // Pasting formatted text is a two-step process: First
- // we paste unformatted text, then overwrite it with
- // formatted text, so that undo restores the
- // pre-formatting syntax.
- add_text_and_select(trimmed_paste_text, $textarea);
- }
- compose_ui.insert_and_scroll_into_view(text, $textarea);
+ do_paste_text(paste_html, paste_text, $textarea);
}
}
}