From b5273b4c2577cb9df56a813da444b0cbc8d0bbea Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Tue, 9 Jul 2013 17:08:33 -0400 Subject: [PATCH] Focus the next open textarea when starting a compose Previously we had fancy logic to determine where to focus, but immediately clobbered any focus choice we made and forced the stream selection to be in focus. We also incorrectly determined what to focus in the case of clicking the new PM button when in a stream narrow. (imported from commit 01e2cec8eca068ee1d45d3cfb21607b981d5034e) --- zephyr/static/js/compose.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/zephyr/static/js/compose.js b/zephyr/static/js/compose.js index dcfbf1b655..e79f3aabdf 100644 --- a/zephyr/static/js/compose.js +++ b/zephyr/static/js/compose.js @@ -34,6 +34,10 @@ function show(tabname, focus_area) { $("#new_message_content").trigger("autosize"); $(".new_message_textarea").css("min-height", "3em"); + if (focus_area !== undefined) { + focus_area.focus().select(); + } + // If the compose box is obscuring the currently selected message, // scroll up until the message is no longer occluded. if (current_msg_list.selected_id() === -1) { @@ -48,8 +52,6 @@ function show(tabname, focus_area) { viewport.user_initiated_animate_scroll(cover+5); } - focus_area.focus().select(); - // Disable the notifications bar if it overlaps with the composebox notifications_bar.maybe_disable(); } @@ -201,9 +203,10 @@ exports.start = function (msg_type, opts) { ui.change_tab_to("#home"); var focus_area; - if (opts.stream && ! opts.subject) { + if (msg_type === 'stream' && opts.stream && ! opts.subject) { focus_area = 'subject'; - } else if (opts.stream || opts.private_message_recipient) { + } else if ((msg_type === 'stream' && opts.stream) + || opts.private_message_recipient) { focus_area = 'new_message_content'; } @@ -427,10 +430,10 @@ exports.set_mode = function (mode) { exports.start(mode); } if (mode === 'private') { - show('private', $("#private_message_recipient")); + show('private'); is_composing_message = "private"; } else { - show('stream', $("#stream")); + show('stream'); is_composing_message = "stream"; } };