compose: Correctly focus when replying to general chat.

This commit is contained in:
Karl Stolley
2025-02-04 14:07:13 -06:00
committed by Tim Abbott
parent 1bc53831c7
commit 30b1ae7111
2 changed files with 14 additions and 3 deletions

View File

@@ -202,13 +202,18 @@ export function maybe_show_scrolling_formatting_buttons(container_selector: stri
function get_focus_area(opts: ComposeTriggeredOptions): string {
// Set focus to "Topic" when narrowed to a stream+topic
// and "Start new conversation" button clicked.
if (opts.message_type === "stream" && opts.stream_id && !opts.topic) {
if (
opts.message_type === "stream" &&
opts.stream_id &&
!opts.topic &&
realm.realm_mandatory_topics
) {
return "input#stream_message_recipient_topic";
} else if (
(opts.message_type === "stream" && opts.stream_id !== undefined) ||
(opts.message_type === "private" && opts.private_message_recipient)
) {
if (opts.trigger === "clear topic button") {
if (opts.trigger === "clear topic button" || opts.trigger === "compose_hotkey") {
return "input#stream_message_recipient_topic";
}
return "textarea#compose-textarea";

View File

@@ -1280,7 +1280,7 @@ run_test("right-to-left", () => {
});
const get_focus_area = compose_ui._get_focus_area;
run_test("get_focus_area", () => {
run_test("get_focus_area", ({override}) => {
assert.equal(get_focus_area({message_type: "private"}), "#private_message_recipient");
assert.equal(
get_focus_area({
@@ -1293,10 +1293,16 @@ run_test("get_focus_area", () => {
get_focus_area({message_type: "stream"}),
"#compose_select_recipient_widget_wrapper",
);
override(realm, "realm_mandatory_topics", true);
assert.equal(
get_focus_area({message_type: "stream", stream_name: "fun", stream_id: 4}),
"input#stream_message_recipient_topic",
);
override(realm, "realm_mandatory_topics", false);
assert.equal(
get_focus_area({message_type: "stream", stream_name: "fun", stream_id: 4}),
"textarea#compose-textarea",
);
assert.equal(
get_focus_area({message_type: "stream", stream_name: "fun", stream_id: 4, topic: "more"}),
"textarea#compose-textarea",