compose: When editing message/s, quote into the last focused edit box.

Until now, when a user quoted and replied to a message, even while
editing another, the quote would be inserted into the compose box. There
was no way to quote into the edit box.

Detecting the edit box to add content too was tricky, since on opening
the message actions popover, that message would be selected, while the
edit box would lose focus.

Now we don't shift focus on opening the message actions popover, keep
track of the last focused textarea and add the quote content to it if
if it's still in the DOM (if the user has not cancelled the editing).

Fixes: #20380.
This commit is contained in:
N-Shar-ma
2023-10-06 04:06:11 +05:30
committed by Tim Abbott
parent 4610c1a257
commit 2c318b680b
3 changed files with 11 additions and 3 deletions

View File

@@ -125,13 +125,19 @@ export function reply_with_mention(opts) {
}
export function quote_and_reply(opts) {
const $textarea = $("textarea#compose-textarea");
const message_id = opts.message_id || message_lists.current.selected_id();
const message = message_lists.current.get(message_id);
const quoting_placeholder = $t({defaultMessage: "[Quoting…]"});
if (!compose_state.has_message_content()) {
// If the last compose type textarea focused on is still in the DOM, we add
// the quote in that textarea, else we default to the compose box.
const $textarea = compose_state.get_last_focused_compose_type_input()?.isConnected
? $(compose_state.get_last_focused_compose_type_input())
: $("textarea#compose-textarea");
if ($textarea.attr("id") === "compose-textarea" && !compose_state.has_message_content()) {
// The user has not started typing a message,
// but is quoting into the compose box,
// so we will re-open the compose box.
// (If you did re-open the compose box, you
// are prone to glitches where you select the
@@ -160,7 +166,7 @@ export function quote_and_reply(opts) {
content += `${fence}quote\n${message.raw_content}\n${fence}`;
compose_ui.replace_syntax(quoting_placeholder, content, $textarea);
compose_ui.autosize_textarea($("textarea#compose-textarea"));
compose_ui.autosize_textarea($textarea);
}
if (message && message.raw_content) {