From b67b9912c4b182019079f7c6ceaffc46e33b36f9 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Wed, 12 May 2021 12:49:05 -0700 Subject: [PATCH] drafts: Fix hook for saving drafts. Previously, the hook to save drafts when closing the compose box was a focusout on #compose-textarea. This mostly worked, and was essentially invisible to users (because the animation to notify you about saved drafts was in the close_compose_ui widget that is hidden), but you'd end up seeing the tooltip appear (in the wrong place) if you closed the compose box immediately after sending a message with Tab+Enter. The correct fix is for the drafts hook to be just before we start clearing compose box state, inside hide_box. This was difficult to catch in a development environment, since one doesn't use that flow with "Enter sends" enabled. --- frontend_tests/node_tests/drafts.js | 4 ---- static/js/compose_actions.js | 2 ++ static/js/drafts.js | 2 -- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/frontend_tests/node_tests/drafts.js b/frontend_tests/node_tests/drafts.js index d93d15b156..030d83ad70 100644 --- a/frontend_tests/node_tests/drafts.js +++ b/frontend_tests/node_tests/drafts.js @@ -174,10 +174,6 @@ test("initialize", (override) => { }; drafts.initialize(); - - const message_content = $("#compose-textarea"); - assert.equal(message_content.get_on_handler("focusout"), drafts.update_draft); - message_content.trigger("focusout"); }); test("remove_old_drafts", () => { diff --git a/static/js/compose_actions.js b/static/js/compose_actions.js index ed45279fbf..2aa6418d14 100644 --- a/static/js/compose_actions.js +++ b/static/js/compose_actions.js @@ -31,6 +31,8 @@ export function blur_compose_inputs() { } function hide_box() { + // This is the main hook for saving drafts when closing the compose box. + drafts.update_draft(); blur_compose_inputs(); $("#stream-message").hide(); $("#private-message").hide(); diff --git a/static/js/drafts.js b/static/js/drafts.js index 7c0944888c..9276f6e08f 100644 --- a/static/js/drafts.js +++ b/static/js/drafts.js @@ -557,8 +557,6 @@ export function initialize() { set_count(Object.keys(draft_model.get()).length); - $("#compose-textarea").on("focusout", update_draft); - $("body").on("focus", ".draft-info-box", (e) => { activate_element(e.target); });