Skip to content

Commit

Permalink
Wait for mouseup event when clicking on a row/cell that is already se…
Browse files Browse the repository at this point in the history
…lected, so as to make it possible to do dnd properly.
  • Loading branch information
kriszyp committed Aug 9, 2012
1 parent b7491c8 commit cd03213
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions Selection.js
Expand Up @@ -14,7 +14,7 @@ return declare([List], {
// selectionEvents: String
// Event (or events, comma-delimited) to listen on to trigger select logic.
// Note: this is ignored in the case of touch devices.
selectionEvents: "mousedown,dgrid-cellfocusin",
selectionEvents: "mousedown,mouseup,dgrid-cellfocusin",

// deselectOnRefresh: Boolean
// If true, the selection object will be cleared when refresh is called.
Expand Down Expand Up @@ -62,12 +62,14 @@ return declare([List], {
// don't run if selection mode is none,
// or if coming from a dgrid-cellfocusin from a mousedown
if(this.selectionMode == "none" ||
(event.type == "dgrid-cellfocusin" && event.parentType == "mousedown")){
(event.type == "dgrid-cellfocusin" && event.parentType == "mousedown") ||
(event.type == "mouseup" && currentTarget != this._waitForMouseUp)){
return;
}
this._waitForMouseUp = null;

var ctrlKey = event.type == "mousedown" ? event[ctrlEquiv] : event.ctrlKey;
if(event.type == "mousedown" || !event.ctrlKey || event.keyCode == 32){
var ctrlKey = !event.keyCode ? event[ctrlEquiv] : event.ctrlKey;
if(!event.keyCode || !event.ctrlKey || event.keyCode == 32){
var mode = this.selectionMode,
row = currentTarget,
rowObj = this.row(row),
Expand All @@ -84,6 +86,10 @@ return declare([List], {
this.select(row);
}
this._lastSelected = row;
}else if(this.selection[rowObj.id] && !event.shiftKey && event.type == "mousedown"){
// we wait for the mouse up if we are clicking a selected item so that drag n' drop
// is possible without losing our selection
this._waitForMouseUp = row;
}else{
var value;
// clear selection first for non-ctrl-clicks in extended mode,
Expand All @@ -104,7 +110,7 @@ return declare([List], {
this._lastSelected = row;
}
}
if(event.type == "mousedown" && (event.shiftKey || ctrlKey)){
if(!event.keyCode && (event.shiftKey || ctrlKey)){
// prevent selection in firefox
event.preventDefault();
}
Expand Down

0 comments on commit cd03213

Please sign in to comment.