Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
compose: Fix restoring big drafts freezes the app.
Aman Agrawal970dd30f9608
diff --git a/web/src/compose_actions.ts b/web/src/compose_actions.tsindex c04ffcb6ad9..bbadbe74e61 100644--- a/web/src/compose_actions.ts+++ b/web/src/compose_actions.ts@@ -347,7 +347,13 @@ export function start(raw_opts: ComposeActionsStartOpts): void {}if (opts.content !== undefined) {- compose_ui.insert_and_scroll_into_view(opts.content, $("textarea#compose-textarea"), true);+ const replace_all_without_undo_support = true;+ compose_ui.insert_and_scroll_into_view(+ opts.content,+ $("textarea#compose-textarea"),+ false,+ replace_all_without_undo_support,+ );$(".compose_control_button_container:has(.add-poll)").addClass("disabled-on-hover");// If we were provided with message content, we might need to// display that it's too long.diff --git a/web/src/compose_ui.ts b/web/src/compose_ui.tsindex 9096751067f..87601a39911 100644--- a/web/src/compose_ui.ts+++ b/web/src/compose_ui.ts@@ -114,8 +114,15 @@ export function insert_and_scroll_into_view(content: string,$textarea: JQuery<HTMLTextAreaElement>,replace_all = false,+ replace_all_without_undo_support = false,): void {- if (replace_all) {+ if (replace_all_without_undo_support) {+ // setFieldText is very slow and noticeable when inserting 10k++ // characters of text like from a drafted response,+ // but we use it since we want to support `undo`. If we don't want+ // to support `undo`, we can use a faster method.+ $textarea.val(content);+ } else if (replace_all) {setFieldText($textarea[0]!, content);} else {insertTextIntoField($textarea[0]!, content);diff --git a/web/tests/compose_actions.test.js b/web/tests/compose_actions.test.jsindex efea43196d7..52f6b430fb6 100644--- a/web/tests/compose_actions.test.js+++ b/web/tests/compose_actions.test.js@@ -143,10 +143,15 @@ test("start", ({override, override_rewire, mock_template}) => {let compose_defaults;override(narrow_state, "set_compose_defaults", () => compose_defaults);- override(compose_ui, "insert_and_scroll_into_view", (content, $textarea, replace_all) => {- $textarea.val(content);- assert.ok(replace_all);- });+ override(+ compose_ui,+ "insert_and_scroll_into_view",+ (content, $textarea, replace_all, replace_all_without_undo_support) => {+ $textarea.val(content);+ assert.ok(!replace_all);+ assert.ok(replace_all_without_undo_support);+ },+ );// Start stream messagecompose_defaults = {