compose: Save messages as drafts when window loses focus.

Add a check for window blur and save any in-progress
messages as drafts. This will help prevent unnecessary
message loss for the user by creating drafts for them more
whenever they switch away from their Zulip tab.

Tested on my local Ubuntu development with a demo
organization and some of the premade profiles.

Fixes #35262.
This commit is contained in:
amcdowell226
2025-08-05 15:28:13 -07:00
committed by GitHub
parent f689dfc3c3
commit 124a32e819
3 changed files with 18 additions and 0 deletions

View File

@@ -18,6 +18,7 @@ import * as compose_state from "./compose_state.ts";
import * as compose_ui from "./compose_ui.ts";
import * as compose_validate from "./compose_validate.ts";
import * as dialog_widget from "./dialog_widget.ts";
import * as drafts from "./drafts.ts";
import * as flatpickr from "./flatpickr.ts";
import {$t_html} from "./i18n.ts";
import * as message_edit from "./message_edit.ts";
@@ -626,6 +627,12 @@ export function initialize() {
compose_recipient.set_high_attention_recipient_row();
});
$(window).on("blur", () => {
// Save drafts when the window loses focus to help
// ensure no work is lost
drafts.update_draft();
});
$("body").on("click", ".formatting_button", function (e) {
const $compose_click_target = $(this);
const $textarea = $compose_click_target.closest("form").find("textarea");