console.log('hi'); var index = -1; // listen onkeydown for n/p to go to next/previous diffs $(window).on('keydown', function(e) { // don't act on already handled events or if the files tab isn't active console.log('detected key press'); console.log(e); if (e.altKey || e.ctrlKey || e.metaKey || e.isDefaultPrevented() || $('textarea').is(':focus')) { return; } var shifty = false; if (e.shiftKey) { var shift = true; } // main nav if (e.which === 49 || e.which === 72) { // 1 console.log('detected 1'); window.location = '/'; } else if (e.which === 50) { // 2 console.log('detected 2'); window.location = '/reviews/'; } else if (e.which === 51) { // 3 console.log('detected 3'); window.location = '/files/'; } else if (e.which === 52) { // 4 console.log('detected 4'); window.location = '/changes/'; } else if (e.which === 191 && e.shiftKey) { // ? console.log('detected ?'); $('a:nth(0)').trigger('click'); } // for activity list if ($('.activity-stream').length) { var updated = false; if (e.which === 74) { // j for next console.log('detected j for next'); index += 1; updated = true; } else if (e.which === 75 && index>0) { // k for previous console.log('detected k for previous'); index = index-1; updated = true; } else if (e.which === 67) { // c for comment console.log('detected c for comment'); window.location = $('.activity-stream tbody tr.active .comment-link a').attr('href'); } else if (e.which === 65) { // a for person console.log('detected a for go to person'); window.location = $('.activity-stream tbody tr.active td:nth(1) a:nth(0)').attr('href'); } else if (e.which === 13) { // enter for changelist or job console.log('detected enter for go to changelist/job'); window.location = $('.activity-stream tbody tr.active td:nth(1) a:nth(1)').attr('href'); } else if (e.which === 88) { // x for read-more console.log('detected x for read more'); if ($('.activity-stream tbody tr.active .expanded').length) { $('.activity-stream tbody tr.active .read-less a').triggerHandler('click'); } else { $('.activity-stream tbody tr.active .read-more a').triggerHandler('click'); } //$('.activity-stream tbody tr.active .read-less a').triggerHandler('click'); } } // for files list if ($('.browse-files').length && $('.browse-tabs li:nth(0).active').length) { var updated = false; if (e.which === 74 && index<($('.browse-files tbody tr').length-1)) { // j for next console.log('detected j for next'); index += 1; updated = true; } else if (e.which === 75 && index>0) { // k for previous console.log('detected k for previous'); index = index-1; updated = true; } else if (e.which === 13) { // enter for changelist or job console.log('detected enter'); //$('.browse-files tbody tr.active a i').triggerHandler('click'); window.location = $('.browse-files tbody tr.active a').attr('href'); } else if (e.which === 79) { // o for home console.log('detected o for home'); window.location = '/'; } else if (e.which === 80) { // p for ALL reviews console.log('detected p for review board'); window.location = '/'; } else if (e.which === 72) { // h for history console.log('detected h for review board'); $('.nav-tabs .icon-time').triggerHandler('click'); } else if (e.which === 88) { // x for read-more console.log('detected q for read more'); if ($('.activity-stream tbody tr.active .expanded').length) { $('.activity-stream tbody tr.active .read-less a').triggerHandler('click'); } else { $('.activity-stream tbody tr.active .read-more a').triggerHandler('click'); } //$('.activity-stream tbody tr.active .read-less a').triggerHandler('click'); } } // for file history if ($('.file-history').length && $('.browse-tabs li:nth(1).active').length) { var updated = false; if (e.which === 74 && index<($('.file-history tbody tr').length-1)) { // j for next console.log('detected j for next'); index += 1; updated = true; } else if (e.which === 75 && index>0) { // k for previous console.log('detected k for previous'); index = index-1; updated = true; } else if (e.which === 13) { // enter console.log('detected enter'); //$('.browse-files tbody tr.active a i').triggerHandler('click'); window.location = $('.file-history tbody tr.active td:nth(0) a:nth(0)').attr('href'); } else if (e.which === 88) { // x for read-more console.log('detected q for read more'); if ($('.file-history tbody tr.active .expanded').length) { $('.file-history tbody tr.active .read-less a').triggerHandler('click'); } else { $('.file-history tbody tr.active .read-more a').triggerHandler('click'); } //$('.activity-stream tbody tr.active .read-less a').triggerHandler('click'); } } // for file history if ($('.change-history').length && $('.browse-tabs li:nth(1).active').length) { var updated = false; if (e.which === 74 && index<($('.change-history tbody tr').length-1)) { // j for next console.log('detected j for next'); index += 1; updated = true; } else if (e.which === 75 && index>0) { // k for previous console.log('detected k for previous'); index = index-1; updated = true; } else if (e.which === 13) { // enter console.log('detected enter'); //$('.browse-files tbody tr.active a i').triggerHandler('click'); window.location = $('.change-history tbody tr.active td:nth(0) a:nth(0)').attr('href'); } else if (e.which === 65) { // a for person console.log('detected a for go to person'); window.location = $('.change-history tbody tr.active td:nth(1) a').attr('href'); } else if (e.which === 88) { // x for read-more console.log('detected q for read more'); if ($('.change-history tbody tr.active .expanded').length) { $('.change-history tbody tr.active .read-less a').triggerHandler('click'); } else { $('.change-history tbody tr.active .read-more a').triggerHandler('click'); } //$('.activity-stream tbody tr.active .read-less a').triggerHandler('click'); } } if ($('.change-files').length) { var updated = false; if (e.which === 74 && index<($('.change-files tbody tr').length-1)) { // j for next console.log('detected j for next'); index += 1; updated = true; } else if (e.which === 75 && index>0) { // k for previous console.log('detected k for previous'); index = index-1; updated = true; } else if (e.which === 13) { // enter console.log('detected enter'); //$('.browse-files tbody tr.active a i').triggerHandler('click'); window.location = $('.change-history tbody tr.active td:nth(0) a:nth(0)').attr('href'); } else if (e.which === 88) { // x for read-more console.log('detected q for read more'); if ($('.change-history tbody tr.active .expanded').length) { $('.change-history tbody tr.active .read-less a').triggerHandler('click'); } else { $('.change-history tbody tr.active .read-more a').triggerHandler('click'); } //$('.activity-stream tbody tr.active .read-less a').triggerHandler('click'); } } if ($('.reviews-table').length) { var updated = false; if (e.which === 74 && index<($('.reviews-table tbody tr').length-2)) { // j for next console.log('detected j for next'); index += 1; updated = true; } else if (e.which === 75 && index>0) { // k for previous console.log('detected k for previous'); index = index-1; updated = true; } else if (e.which === 13) { // enter console.log('detected enter'); //$('.browse-files tbody tr.active a i').triggerHandler('click'); window.location = $('.reviews-table tbody tr.active td:nth(0) a:nth(0)').attr('href'); } else if (e.which === 88) { // x for read-more console.log('detected q for read more'); if ($('.reviews-table tbody tr.active .expanded').length) { $('.reviews-table tbody tr.active .read-less a').triggerHandler('click'); } else { $('.reviews-table tbody tr.active .read-more a').triggerHandler('click'); } //$('.activity-stream tbody tr.active .read-less a').triggerHandler('click'); } } if (updated) { if ($('.browse-files' && $('.browse-tabs li:nth(0).active').length).length) { var focusedActivity = $('.browse-files tbody tr:nth(' + index + ')'); var activeActivity = $('.browse-files tbody tr.active'); console.log('YOU ARE LOOKING AT FILES'); } else if ($('.activity-stream').length) { var focusedActivity = $('.activity-stream tbody tr:nth(' + index + ')'); var activeActivity = $('.activity-stream tbody tr.active'); console.log('YOU ARE LOOKING AT ACTIVITY'); } else if ($('.file-history').length && $('.browse-tabs li:nth(1).active').length) { var focusedActivity = $('.file-history tbody tr:nth(' + index + ')'); var activeActivity = $('.file-history tbody tr.active'); console.log('YOU ARE LOOKING AT FILE HISTORY'); } else if ($('.change-history' && $('.browse-tabs li:nth(1).active').length).length) { var focusedActivity = $('.change-history tbody tr:nth(' + index + ')'); var activeActivity = $('.change-history tbody tr.active'); console.log('YOU ARE LOOKING AT CHANGE HISTORY'); } else if ($('.change-files').length) { var focusedActivity = $('.change-files .diff-wrapper:nth(' + index + ')'); var activeActivity = $('.change-files .diff-wrapper.active'); console.log('YOU ARE LOOKING AT CHANGE FILES'); } else if ($('.reviews-table').length) { var focusedActivity = $('.reviews-table tbody tr:nth(' + index + ')'); var activeActivity = $('.reviews-table tbody tr.active'); console.log('YOU ARE LOOKING AT REVIEWS TABLE'); } activeActivity.removeClass('active'); focusedActivity.addClass('active'); console.log(index); if (focusedActivity.length) { $('html, body').animate({ scrollTop: focusedActivity.offset().top - 300 }, 0); } e.preventDefault(); } });
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 8484 | Allan Yu |
Fixed bugs: * Styling of hotkey help dialog (open with '?') no longer messes with other modal dialogs in Swarm * Key presses won't override key presses when focusing on a text box. * Fixed styling of highlighted rows New features: * Use J/K to cycle through files in a changelist or review. Use ENTER or X to expand/collapse the file * Use '5' to jump to 'Jobs' * Updated hotkey help dialog (open with '?') |
||
#1 | 8400 | Matt Attaway |
Add the 'Bee Keys' Swarm extension This extension adds hotkeys to navigate the Swarm interface. Once installed press '?' for details. |