Skip to content

Commit

Permalink
Fix: Allow for selection of text before items are selected in the table
Browse files Browse the repository at this point in the history
- Rather than checking for an empty selection, need to check to see if the selection has changed from mousedown to the click event
- https://datatables.net/forums/discussion/comment/127487#Comment_127487
  • Loading branch information
Allan Jardine committed Mar 19, 2018
1 parent 122c174 commit 8c59e62
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion js/dataTables.select.js
Expand Up @@ -324,6 +324,7 @@ function enableMouseSelection ( dt )
var container = $( dt.table().container() );
var ctx = dt.settings()[0];
var selector = ctx._select.selector;
var matchSelection;

container
.on( 'mousedown.dtSelect', selector, function(e) {
Expand All @@ -336,6 +337,10 @@ function enableMouseSelection ( dt )
return false;
} );
}

if ( window.getSelection ) {
matchSelection = window.getSelection();
}
} )
.on( 'mouseup.dtSelect', selector, function() {
// Allow text selection to occur again, Mozilla style (tested in FF
Expand All @@ -354,7 +359,7 @@ function enableMouseSelection ( dt )
// If the element that contains the selection is not in the table, we can ignore it
// This can happen if the developer selects text from the click event
if ( ! selection.anchorNode || $(selection.anchorNode).closest('table')[0] === dt.table().node() ) {
if ( $.trim(selection.toString()) !== '' ) {
if ( selection !== matchSelection ) {
return;
}
}
Expand Down

0 comments on commit 8c59e62

Please sign in to comment.