1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-02-20 21:26:53 +00:00

(trunk web) #4271 "selecting multiple files with shift-arrow doesn't work" -- fixed.

This commit is contained in:
Jordan Lee 2011-08-25 10:23:19 +00:00
parent dd762bc7ea
commit 398ee0cc18

View file

@ -72,6 +72,7 @@ Transmission.prototype =
$('#preferences_link').bind('click', function(e) { tr.releaseClutchPreferencesButton(e); }); $('#preferences_link').bind('click', function(e) { tr.releaseClutchPreferencesButton(e); });
} else { } else {
$(document).bind('keydown', function(e) { tr.keyDown(e); }); $(document).bind('keydown', function(e) { tr.keyDown(e); });
$(document).bind('keyup', function(e) { tr.keyUp(e); });
$('#torrent_container').click(function() { tr.deselectAll(true); }); $('#torrent_container').click(function() { tr.deselectAll(true); });
$('#inspector_link').click(function(e) { tr.toggleInspectorClicked(e); }); $('#inspector_link').click(function(e) { tr.toggleInspectorClicked(e); });
@ -442,30 +443,31 @@ Transmission.prototype =
delete this._last_torrent_clicked; delete this._last_torrent_clicked;
}, },
indexOfLastTorrent: function() {
for (var i=0, r; r=this._rows[i]; ++i)
if (r.getTorrent().getId() === this._last_torrent_clicked)
return i;
return -1;
},
/* Select a range from this torrent to the last clicked torrent */ /* Select a range from this torrent to the last clicked torrent */
selectRange: function(row) selectRange: function(row)
{ {
if (!this._last_torrent_clicked) { var last = this.indexOfLastTorrent();
this.selectRow(row);
} else { // select the range between the prevous & current
var prev = null; if (last === -1)
var next = null; {
for (var i=0, r; r=this._rows[i]; ++i) { this.selectRow(row);
if (r.getTorrent().getId() === this._last_torrent_clicked) }
prev = i; else // select the range between the prevous & current
if (r === row) {
next = i; var next = this._rows.indexOf(row);
} var min = Math.min(last, next);
if ((prev!==null) && (next!==null)) { var max = Math.max(last, next);
var min = Math.min(prev, next); for (var i=min; i<=max; ++i)
var max = Math.max(prev, next); this.selectRow(this._rows[i]);
for (i=min; i<=max; ++i)
this.selectRow(this._rows[i]);
}
} }
//this._last_row_clicked = row
this.callSelectionChangedSoon(); this.callSelectionChangedSoon();
}, },
@ -501,26 +503,57 @@ Transmission.prototype =
{ {
var up = ev.keyCode === 38; // up key pressed var up = ev.keyCode === 38; // up key pressed
var dn = ev.keyCode === 40; // down key pressed var dn = ev.keyCode === 40; // down key pressed
var shift = ev.keyCode === 16; // shift key pressed
if (up || dn) if (up || dn)
{ {
var rows = this._rows; var rows = this._rows;
// find the first selected row var last = this.indexOfLastTorrent();
for (var i=0, row; row=rows[i]; ++i) var i = last;
if (row.isSelected())
break;
if (i == rows.length) // no selection yet if (i === -1) // no selection yet
i = 0; i = 0;
else if (dn) else if (dn)
i = (i+1) % rows.length; i = (i+1) % rows.length;
else if (up) else if (up)
i = (i || rows.length) - 1; i = (i || rows.length) - 1;
r = rows[i];
this.setSelectedRow(rows[i]); if (this._shift_index >= 0)
this.scrollToRow(rows[i]); {
// user is extending the selection with the shift + arrow keys...
if ( ((this._shift_index <= last) && (last < i))
|| ((this._shift_index >= last) && (last > i)))
{
this.selectRow(r);
}
else if (((this._shift_index >= last) && (i > last))
|| ((this._shift_index <= last) && (last > i)))
{
this.deselectRow(rows[last]);
}
}
else
{
if (ev.shiftKey)
this.selectRange(r);
else
this.setSelectedRow(r);
}
this._last_torrent_clicked = r.getTorrent().getId();
this.scrollToRow(r);
} }
else if (shift)
{
this._shift_index = this.indexOfLastTorrent();
}
},
keyUp: function(ev)
{
if (ev.keyCode === 16) // shift key pressed
delete this._shift_index;
}, },
isButtonEnabled: function(e) { isButtonEnabled: function(e) {