diff --git a/static/js/hotkey.js b/static/js/hotkey.js index c09d579378..bb67af1707 100644 --- a/static/js/hotkey.js +++ b/static/js/hotkey.js @@ -67,8 +67,12 @@ function get_event_name(e) { return 'search'; case 63: // '?': Show keyboard shortcuts page return 'show_shortcuts'; + case 65: // 'A' + return 'stream_cycle_backward'; case 67: // 'C' return 'compose_private_message'; + case 68: // 'D' + return 'stream_cycle_forward'; case 74: // 'J' return 'page_down'; case 75: // 'K' @@ -271,6 +275,12 @@ function process_hotkey(e) { case 'show_shortcuts': // Show keyboard shortcuts page $('#keyboard-shortcuts').modal('show'); return true; + case 'stream_cycle_backward': + navigate.cycle_stream('backward'); + return true; + case 'stream_cycle_forward': + navigate.cycle_stream('forward'); + return true; } if (current_msg_list.empty()) { diff --git a/static/js/navigate.js b/static/js/navigate.js index 6fbdac3fca..5e54545c73 100644 --- a/static/js/navigate.js +++ b/static/js/navigate.js @@ -70,5 +70,37 @@ exports.page_down = function () { } }; +exports.cycle_stream = function (direction) { + var currentStream, nextStream; + if (narrow.stream() !== undefined) { + currentStream = stream_list.get_stream_li(narrow.stream()); + } + switch (direction) { + case 'forward': + if (narrow.stream() === undefined) { + nextStream = $("#stream_filters").children().first(); + } else { + nextStream = currentStream.next(); + if (nextStream.length === 0) { + nextStream = $("#stream_filters").children().first(); + } + } + break; + case 'backward': + if (narrow.stream() === undefined) { + nextStream = $("#stream_filters").children().last(); + } else { + nextStream = currentStream.prev(); + if (nextStream.length === 0) { + nextStream = $("#stream_filters").children().last(); + } + } + break; + default: + blueslip.error("Invalid parameter to cycle_stream", {value: direction}); + } + narrow.by('stream', nextStream.data('name')); +}; + return exports; }()); diff --git a/templates/zerver/keyboard_shortcuts.html b/templates/zerver/keyboard_shortcuts.html index ed7afd0f64..365930e022 100644 --- a/templates/zerver/keyboard_shortcuts.html +++ b/templates/zerver/keyboard_shortcuts.html @@ -94,6 +94,10 @@