From 50c03d585da10e4eabad9ddf8a8b4688adb94ef0 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Sun, 28 Aug 2011 19:30:17 +0000 Subject: [PATCH] (trunk web) selecting the up arrow when no transfers are selected selects the bottom transfer; eliminate an error when pushing the up/down arrow keys with a blank torrent list --- web/javascript/transmission.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/web/javascript/transmission.js b/web/javascript/transmission.js index b86361a17..061412c0f 100644 --- a/web/javascript/transmission.js +++ b/web/javascript/transmission.js @@ -481,23 +481,31 @@ Transmission.prototype = keyDown: function(ev) { var handled = false, + rows = this._rows, up = ev.keyCode === 38; // up key pressed dn = ev.keyCode === 40, // down key pressed shift = ev.keyCode === 16; // shift key pressed - if (up || dn) + if ((up || dn) && rows.length) { - var rows = this._rows, - last = this.indexOfLastTorrent(), + var last = this.indexOfLastTorrent(), i = last, anchor = this._shift_index; - if (i === -1) // no selection yet - i = 0; - else if (dn) - i = (i+1) % rows.length; - else if (up) - i = (i || rows.length) - 1; + if (dn) + { + if (i === -1) // no selection yet + i = 0; + else + i = (i+1) % rows.length; + } + else + { + if (i === -1) // no selection yet + i = rows.length - 1; + else + i = (i || rows.length) - 1; + } var r = rows[i]; if (anchor >= 0)