hotkeys: Add "p" to narrow to next unread PM thread.

This works simimlar to the "n" key for next topics.

This commit does a few things:

    * It wires up the hotkey to an existing function
      that could change narrows.
    * It adds documentation.
    * It adds logic to make sure the compose box does
      not open.

@showell helped a bit with the wording of comments here.

Fixes #4874
This commit is contained in:
Abhigyan Khaund
2018-02-16 20:26:25 +05:30
committed by Steve Howell
parent 68664acf1f
commit a75f0aa594
6 changed files with 33 additions and 4 deletions

View File

@@ -148,7 +148,7 @@ function stubbing(func_name_to_stub, test_function) {
// Unmapped keys should immediately return false, without // Unmapped keys should immediately return false, without
// calling any functions outside of hotkey.js. // calling any functions outside of hotkey.js.
assert_unmapped('abefhlmoptxyz'); assert_unmapped('abefhlmotxyz');
assert_unmapped('BEFHILNOQTUWXYZ'); assert_unmapped('BEFHILNOQTUWXYZ');
// We have to skip some checks due to the way the code is // We have to skip some checks due to the way the code is
@@ -286,6 +286,7 @@ function stubbing(func_name_to_stub, test_function) {
// Test keys that work when a message is selected and // Test keys that work when a message is selected and
// also when the message list is empty. // also when the message list is empty.
assert_mapping('n', 'narrow.narrow_to_next_topic'); assert_mapping('n', 'narrow.narrow_to_next_topic');
assert_mapping('p', 'narrow.narrow_to_next_pm_string');
global.current_msg_list.empty = return_true; global.current_msg_list.empty = return_true;
assert_mapping('n', 'narrow.narrow_to_next_topic'); assert_mapping('n', 'narrow.narrow_to_next_topic');

View File

@@ -384,7 +384,17 @@ exports.quote_and_reply = function (opts) {
}); });
}; };
exports.on_narrow = function () { exports.on_narrow = function (opts) {
// We use force_close when jumping between PM narrows with the "p" key,
// so that we don't have an open compose box that makes it difficult
// to cycle quickly through unread messages.
if (opts.force_close) {
// This closes the compose box if it was already open, and it is
// basically a noop otherwise.
exports.cancel();
return;
}
if (narrow_state.narrowed_by_topic_reply()) { if (narrow_state.narrowed_by_topic_reply()) {
exports.on_topic_narrow(); exports.on_topic_narrow();
return; return;

View File

@@ -94,6 +94,7 @@ var keypress_mappings = {
106: {name: 'vim_down', message_view_only: true}, // 'j' 106: {name: 'vim_down', message_view_only: true}, // 'j'
107: {name: 'vim_up', message_view_only: true}, // 'k' 107: {name: 'vim_up', message_view_only: true}, // 'k'
110: {name: 'n_key', message_view_only: false}, // 'n' 110: {name: 'n_key', message_view_only: false}, // 'n'
112: {name: 'p_key', message_view_only: false}, // 'p'
113: {name: 'query_streams', message_view_only: false}, // 'q' 113: {name: 'query_streams', message_view_only: false}, // 'q'
114: {name: 'reply_message', message_view_only: true}, // 'r' 114: {name: 'reply_message', message_view_only: true}, // 'r'
115: {name: 'narrow_by_recipient', message_view_only: true}, // 's' 115: {name: 'narrow_by_recipient', message_view_only: true}, // 's'
@@ -630,6 +631,9 @@ exports.process_hotkey = function (e, hotkey) {
case 'n_key': case 'n_key':
narrow.narrow_to_next_topic(); narrow.narrow_to_next_topic();
return true; return true;
case 'p_key':
narrow.narrow_to_next_pm_string();
return true;
case 'open_drafts': case 'open_drafts':
drafts.launch(); drafts.launch();
return true; return true;

View File

@@ -248,7 +248,7 @@ exports.activate = function (raw_operators, opts) {
$('#search_query').val(Filter.unparse(operators)); $('#search_query').val(Filter.unparse(operators));
search.update_button_visibility(); search.update_button_visibility();
compose_actions.on_narrow(); compose_actions.on_narrow(opts);
var current_filter = narrow_state.get_current_filter(); var current_filter = narrow_state.get_current_filter();
@@ -361,8 +361,8 @@ exports.narrow_to_next_topic = function () {
exports.activate(filter_expr, opts); exports.activate(filter_expr, opts);
}; };
exports.narrow_to_next_pm_string = function () { exports.narrow_to_next_pm_string = function () {
var curr_pm = narrow_state.pm_string(); var curr_pm = narrow_state.pm_string();
var next_pm = topic_generator.get_next_unread_pm_string(curr_pm); var next_pm = topic_generator.get_next_unread_pm_string(curr_pm);
@@ -379,8 +379,10 @@ exports.narrow_to_next_pm_string = function () {
{operator: 'pm-with', operand: pm_with}, {operator: 'pm-with', operand: pm_with},
]; ];
// force_close parameter is true to not auto open compose_box
var opts = { var opts = {
select_first_unread: true, select_first_unread: true,
force_close: true,
}; };
exports.activate(filter_expr, opts); exports.activate(filter_expr, opts);

View File

@@ -35,6 +35,8 @@ below, and add more to your repertoire as needed.
* **Next unread topic**: `n` * **Next unread topic**: `n`
* **Next unread private message**: `p`
* **All private messages**: `P` * **All private messages**: `P`
* **Search messages**: `/` * **Search messages**: `/`
@@ -66,6 +68,8 @@ below, and add more to your repertoire as needed.
* **Narrow to next unread topic**: `n` * **Narrow to next unread topic**: `n`
* **Narrow to next unread private message**: `p`
* **Narrow to stream**: `s` * **Narrow to stream**: `s`
* **Narrow to topic**: `S` * **Narrow to topic**: `S`

View File

@@ -40,6 +40,10 @@
<td class="hotkey">n</td> <td class="hotkey">n</td>
<td class="definition">{% trans %}Next unread topic{% endtrans %}</td> <td class="definition">{% trans %}Next unread topic{% endtrans %}</td>
</tr> </tr>
<tr>
<td class="hotkey">p</td>
<td class="definition">{% trans %}Next unread private message{% endtrans %}</td>
</tr>
<tr> <tr>
<td class="hotkey">P</td> <td class="hotkey">P</td>
<td class="definition">{% trans %}All private messages{% endtrans %}</td> <td class="definition">{% trans %}All private messages{% endtrans %}</td>
@@ -170,6 +174,10 @@
<td class="hotkey">n</td> <td class="hotkey">n</td>
<td class="definition">{% trans %}Narrow to next unread topic{% endtrans %}</td> <td class="definition">{% trans %}Narrow to next unread topic{% endtrans %}</td>
</tr> </tr>
<tr>
<td class="hotkey">p</td>
<td class="definition">{% trans %}Narrow to next unread private message{% endtrans %}</td>
</tr>
<tr> <tr>
<td class="hotkey">A, D</td> <td class="hotkey">A, D</td>
<td class="definition">{% trans %}Cycle between stream narrows{% endtrans %}</td> <td class="definition">{% trans %}Cycle between stream narrows{% endtrans %}</td>