Skip to content

Commit a1bbc0c

Browse files
committed
fix(Selection): Prevent IE from selecting text
On shift+select, IE was selecting a big range of text. To prevent this we need to add a mousedown handler on the select button to prevent starting a selection. Fixes #3392
1 parent 9b2c6d5 commit a1bbc0c

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

src/features/selection/js/selection.js

+30-13
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@
461461
}
462462

463463
if (selected && noUnselect){
464-
// don't deselect the row
464+
// don't deselect the row
465465
} else if (row.enableSelection !== false) {
466466
row.setSelected(!selected);
467467
if (row.isSelected === true) {
@@ -642,27 +642,27 @@
642642

643643
uiGridCtrl.grid.addRowHeaderColumn(selectionRowHeaderDef);
644644
}
645-
645+
646646
var processorSet = false;
647-
647+
648648
var processSelectableRows = function( rows ){
649649
rows.forEach(function(row){
650650
row.enableSelection = uiGridCtrl.grid.options.isRowSelectable(row);
651651
});
652652
return rows;
653653
};
654-
654+
655655
var updateOptions = function(){
656656
if (uiGridCtrl.grid.options.isRowSelectable !== angular.noop && processorSet !== true) {
657657
uiGridCtrl.grid.registerRowsProcessor(processSelectableRows, 500);
658658
processorSet = true;
659659
}
660660
};
661-
661+
662662
updateOptions();
663663

664664
var dataChangeDereg = uiGridCtrl.grid.registerDataChangeCallback( updateOptions, [uiGridConstants.dataChange.OPTIONS] );
665-
665+
666666
$scope.$on( '$destroy', dataChangeDereg);
667667
},
668668
post: function ($scope, $elm, $attrs, uiGridCtrl) {
@@ -673,8 +673,8 @@
673673
};
674674
}]);
675675

676-
module.directive('uiGridSelectionRowHeaderButtons', ['$templateCache', 'uiGridSelectionService',
677-
function ($templateCache, uiGridSelectionService) {
676+
module.directive('uiGridSelectionRowHeaderButtons', ['$templateCache', 'uiGridSelectionService', 'gridUtil',
677+
function ($templateCache, uiGridSelectionService, gridUtil) {
678678
return {
679679
replace: true,
680680
restrict: 'E',
@@ -683,8 +683,18 @@
683683
require: '^uiGrid',
684684
link: function($scope, $elm, $attrs, uiGridCtrl) {
685685
var self = uiGridCtrl.grid;
686-
$scope.selectButtonClick = function(row, evt) {
686+
$scope.selectButtonClick = selectButtonClick;
687+
688+
// On IE, prevent mousedowns on the select button from starting a selection.
689+
// If this is not done and you shift+click on another row, the browser will select a big chunk of text
690+
if (gridUtil.detectBrowser() === 'ie') {
691+
$elm.on('mousedown', selectButtonMouseDown);
692+
}
693+
694+
695+
function selectButtonClick(row, evt) {
687696
evt.stopPropagation();
697+
688698
if (evt.shiftKey) {
689699
uiGridSelectionService.shiftSelect(self, row, evt, self.options.multiSelect);
690700
}
@@ -694,7 +704,14 @@
694704
else {
695705
uiGridSelectionService.toggleRowSelection(self, row, evt, (self.options.multiSelect && !self.options.modifierKeysToMultiSelect), self.options.noUnselect);
696706
}
697-
};
707+
}
708+
709+
function selectButtonMouseDown(evt) {
710+
if (evt.ctrlKey || evt.shiftKey) {
711+
evt.target.onselectstart = function () { return false; };
712+
window.setTimeout(function () { evt.target.onselectstart = null; }, 0);
713+
}
714+
}
698715
}
699716
};
700717
}]);
@@ -814,7 +831,7 @@
814831
var selectCells = function(evt){
815832
// if we get a click, then stop listening for touchend
816833
$elm.off('touchend', touchEnd);
817-
834+
818835
if (evt.shiftKey) {
819836
uiGridSelectionService.shiftSelect($scope.grid, $scope.row, evt, $scope.grid.options.multiSelect);
820837
}
@@ -825,7 +842,7 @@
825842
uiGridSelectionService.toggleRowSelection($scope.grid, $scope.row, evt, ($scope.grid.options.multiSelect && !$scope.grid.options.modifierKeysToMultiSelect), $scope.grid.options.noUnselect);
826843
}
827844
$scope.$apply();
828-
845+
829846
// don't re-enable the touchend handler for a little while - some devices generate both, and it will
830847
// take a little while to move your hand from the mouse to the screen if you have both modes of input
831848
$timeout(function() {
@@ -848,7 +865,7 @@
848865
// short touch
849866
selectCells(evt);
850867
}
851-
868+
852869
// don't re-enable the click handler for a little while - some devices generate both, and it will
853870
// take a little while to move your hand from the screen to the mouse if you have both modes of input
854871
$timeout(function() {

0 commit comments

Comments
 (0)