Re-focus on the compose box after a send, auto-move cursor

Re-focuses on the compose box after a send, under these conditions:
1) narrowed to stream+subject -or- responding to PM/huddle
2) compose was initiated by clicking on a message or hitting "r"/"enter"
3) cursor has not moved since you've started the composition

Additionally, if you are thus narrowed, we will move your cursor when you've sent
a message to that message, assuming that such a message initially appears visible.

(imported from commit 373c858081694e6fc9994639340a847d66edb566)
This commit is contained in:
acrefoot
2013-05-16 17:16:15 -04:00
parent 66b93d5cfd
commit 6ae117ea5f
3 changed files with 47 additions and 3 deletions

View File

@@ -357,9 +357,12 @@ function send_message() {
$("#compose-send-button").removeAttr('disabled'); $("#compose-send-button").removeAttr('disabled');
$("#sending-indicator").hide(); $("#sending-indicator").hide();
send_status.hide(); send_status.hide();
if (respond_to_cursor) { if (respond_to_cursor && narrow.narrowed_by_reply()) {
respond_to_message({trigger: 'autorespond'}); respond_to_message({trigger: 'autorespond'});
} }
else {
respond_to_cursor = false;
}
}, },
error: function (xhr, error_type) { error: function (xhr, error_type) {
if (error_type !== 'timeout' && reload.is_pending()) { if (error_type !== 'timeout' && reload.is_pending()) {

View File

@@ -628,6 +628,20 @@ exports.narrowed_to_pms = function () {
return false; return false;
}; };
// We auto-reply under certain conditions, namely when you're narrowed
// to a PM (or huddle), and when you're narrowed to some stream/subject pair
exports.narrowed_by_reply = function () {
if (narrow.filter() === undefined) {
return false;
}
var operators = narrow.filter().operators();
return ((operators.length === 1 &&
operators[0][0] === "pm-with") ||
(operators.length === 2 &&
operators[0][0] === "stream" &&
operators[1][0] === "subject"));
};
return exports; return exports;
}()); }());

View File

@@ -188,6 +188,7 @@ function respond_to_message(opts) {
'private_message_recipient': pm_recipient, 'private_message_recipient': pm_recipient,
'replying_to_message': message, 'replying_to_message': message,
'trigger': opts.trigger}); 'trigger': opts.trigger});
} }
// Returns messages from the given message list in the specified range, inclusive // Returns messages from the given message list in the specified range, inclusive
@@ -310,7 +311,7 @@ function process_read_messages(messages) {
// If we ever materially change the algorithm for this function, we // If we ever materially change the algorithm for this function, we
// may need to update notifications.received_messages as well. // may need to update notifications.received_messages as well.
function process_visible_unread_messages() { function process_visible_unread_messages(update_cursor) {
// For any messages visible on the screen, make sure they have been marked // For any messages visible on the screen, make sure they have been marked
// as unread. // as unread.
if (! notifications.window_has_focus()) { if (! notifications.window_has_focus()) {
@@ -336,6 +337,22 @@ function process_visible_unread_messages() {
return (row_height > height && row_offset.top > top) || within_viewport(row_offset, row_height); return (row_height > height && row_offset.top > top) || within_viewport(row_offset, row_height);
}); });
if (update_cursor) {
//save the state of respond_to_cursor, and reapply it every time we move the cursor
var probably_from_sent_message = respond_to_cursor;
$.map(visible_messages, function(msg) {
if ((current_msg_list.get(rows.id($(msg))).sender_email === page_params.email) &&
(current_msg_list.selected_message().id < rows.id($(msg)))) {
// every time we move the cursor, we set respond_to_cursor to false. This should only
// happen if the user initiated the cursor move, not us, so we reset it when processing
// these messages
current_msg_list.select_id(rows.id($(msg)), {then_scroll: true,
from_scroll: true});
respond_to_cursor = probably_from_sent_message;
}
});
}
var mark_as_read = $.map(visible_messages, function(msg) { var mark_as_read = $.map(visible_messages, function(msg) {
var message = current_msg_list.get(rows.id($(msg))); var message = current_msg_list.get(rows.id($(msg)));
if (! unread.message_unread(message)) { if (! unread.message_unread(message)) {
@@ -396,6 +413,7 @@ $(function () {
keepTracking: true}); keepTracking: true});
$(document).on('message_selected.zephyr', function (event) { $(document).on('message_selected.zephyr', function (event) {
// Narrowing is a temporary view on top of the home view and // Narrowing is a temporary view on top of the home view and
// doesn't affect your pointer in the home view. // doesn't affect your pointer in the home view.
if (event.msg_list === home_msg_list if (event.msg_list === home_msg_list
@@ -853,7 +871,16 @@ function get_updates(options) {
// notifications.received_messages uses values set by // notifications.received_messages uses values set by
// process_visible_unread_messages and thus must // process_visible_unread_messages and thus must
// be called after it // be called after it
process_visible_unread_messages(); var i;
var update_cursor = false;
// check if we need to update the cursor, and do so if needed.
for (i = 0; i < messages.length; i++) {
if (messages[i].sender_email === page_params.email && narrow.narrowed_by_reply()) {
update_cursor = true;
}
}
process_visible_unread_messages(update_cursor);
notifications.received_messages(messages); notifications.received_messages(messages);
compose.update_faded_messages(); compose.update_faded_messages();
stream_list.update_streams_sidebar(); stream_list.update_streams_sidebar();