New submission from Ezio Melotti <ezio.melo...@gmail.com>:
The attached patch adds keyboard shortcuts to navigate through the messages to
the tracker.
There are two different "modes":
* mnemonics:
f: first message;
p: previous message;
n: next message;
l: last message;
r: reply (jumps on the comment field and focuses it);
* vim-style:
h: first message;
k: previous message;
j: next message;
l: last message;
i: insert-mode (jumps on the comment field and focuses it);
esc: normal-mode (unfocus the field and re-enables the commands);
It might be nice to add also a command to submit the message, maybe ctrl+enter
or 's' (but this is a bit risky).
----------
assignedto: ezio.melotti
files: issue422.diff
messages: 2257
nosy: eric.araujo, ezio.melotti, r.david.murray
priority: feature
status: unread
title: Keyboard shortcuts
_______________________________________________________
PSF Meta Tracker <metatrac...@psf.upfronthosting.co.za>
<http://psf.upfronthosting.co.za/roundup/meta/issue422>
_______________________________________________________
Index: issue.item.js
===================================================================
--- issue.item.js (revision 88881)
+++ issue.item.js (working copy)
@@ -45,21 +45,72 @@
$(document).ready(function() {
- /* When the user hits the 'end' key the first time, jump to the last
- message rather than to the end of the page. After that restore the
- normal 'end' behavior. */
- // get the offset to the last message
- var offset = $('table.messages tr th a:last').offset()
+ /* Keyboard shortcuts */
+ function is_editing(node) {
+ // return true if the focus is on a form element
+ var element = node.nodeName;
+ return ((element == 'TEXTAREA') || (element == 'SELECT') ||
+ (element == 'INPUT' && node.type != 'file'));
+ }
+ function scroll_to(node) {
+ // scroll to page to the given node
+ window.scrollTo(0, node.offset().top)
+ }
+ var textarea = $('textarea').first();
+ var messages = $('table.messages tr th a:first-child');
+ var last_index = messages.length - 1;
+ // start from -1 so 'n' sends to the first message at the beginning
+ var current = -1;
$(document).keydown(function (event) {
- var node = event.target.nodeName;
- // 35 == end key. Don't do anything if the focus is on form elements
- if ((event.keyCode == 35) && (node != 'TEXTAREA')
- && (node != 'INPUT') && (node != 'SELECT')) {
- // jump at the last message and restore the usual behavior
- window.scrollTo(0, offset.top);
- $(document).unbind('keydown')
- return false;
+ // disable the shortcuts while editing form elements
+ if (is_editing(event.target)) {
+ // unfocus the form when the user press ESC
+ if (event.keyCode == 27) {
+ $(event.target).blur();
+ return false;
+ }
+ return true;
}
+
+ // support two groups of shortcuts for first/prev/next/last/reply:
+ // mnemonics: f/p/n/l/r
+ // vim-style: h/k/j/l/i
+ switch (event.which) {
+ // f/h - first
+ case 70:
+ case 72:
+ scroll_to(messages.first());
+ current = 0;
+ return false;
+ // p/k - previous
+ case 80:
+ case 75:
+ if (current <= 0)
+ return true;
+ current = current - 1;
+ scroll_to(messages.eq(current));
+ return false;
+ // n/j - next
+ case 78:
+ case 74:
+ if (current >= last_index)
+ return true;
+ current = current + 1;
+ scroll_to(messages.eq(current));
+ return false;
+ // l - last
+ case 76:
+ scroll_to(messages.last());
+ current = last_index;
+ return false;
+ case 82:
+ case 73:
+ scroll_to(textarea);
+ textarea.focus();
+ return false;
+ default:
+ return true;
+ }
});
})
_______________________________________________
Tracker-discuss mailing list
Tracker-discuss@python.org
http://mail.python.org/mailman/listinfo/tracker-discuss