From fd4246def52f9b0fa226a7f36dd1f310960b79f5 Mon Sep 17 00:00:00 2001 From: evykassirer Date: Tue, 19 Mar 2024 15:34:10 -0700 Subject: [PATCH] drafts: Append a space to draft when restoring it. If a user starts typing before they see that a draft was restored, this makes that experience a little smoother by adding some separation between the old draft and the new text. --- web/e2e-tests/drafts.test.ts | 4 ++-- web/src/compose_actions.ts | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/web/e2e-tests/drafts.test.ts b/web/e2e-tests/drafts.test.ts index 308e36c6b2..a1cd12f635 100644 --- a/web/e2e-tests/drafts.test.ts +++ b/web/e2e-tests/drafts.test.ts @@ -54,7 +54,7 @@ async function test_restore_stream_message_draft_by_opening_compose_box(page: Pa await common.check_compose_state(page, { stream: "Denmark", topic: "tests", - content: "Test stream message.", + content: "Test stream message. ", }); await page.click("#compose_close"); await page.waitForSelector("#send_message_form", {visible: false}); @@ -74,7 +74,7 @@ async function test_restore_private_message_draft_by_opening_composebox(page: Pa await page.waitForSelector("#private_message_recipient", {visible: true}); await common.check_form_contents(page, "form#send_message_form", { - content: "Test direct message.", + content: "Test direct message. ", }); await page.click("#compose_close"); await page.waitForSelector("#private_message_recipient", {visible: false}); diff --git a/web/src/compose_actions.ts b/web/src/compose_actions.ts index 3df09dd60a..3b4dae39b6 100644 --- a/web/src/compose_actions.ts +++ b/web/src/compose_actions.ts @@ -312,7 +312,12 @@ export function start(raw_opts: ComposeActionsStartOpts): void { const possible_last_draft = drafts.get_last_draft_based_on_compose_state(); if (possible_last_draft !== undefined) { opts.draft_id = possible_last_draft.id; - opts.content = possible_last_draft.content; + // Add a space at the end so that if the user starts typing + // as soon as the composebox opens, they have a bit of separation + // from the restored draft. This won't result in a long trail of + // spaces if a draft is restored several times, because we trim + // whitespace whenever we save drafts. + opts.content = possible_last_draft.content + " "; } }