Skip to content

Commit

Permalink
fix(selection): prevent cell to be selected when user scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
dloeda authored and mportuga committed Dec 19, 2018
1 parent f275aa2 commit a537f0c
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/features/selection/js/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,9 @@
scope: false,
link: function ($scope, $elm, $attrs, uiGridCtrl) {
var touchStartTime = 0,
touchTimeout = 300;
touchStartPos = {},
touchTimeout = 300,
touchPosDiff = 100;

// Bind to keydown events in the render container
if (uiGridCtrl.grid.api.cellNav) {
Expand Down Expand Up @@ -969,20 +971,27 @@
}, touchTimeout);
};

var touchStart = function () {
var touchStart = function (evt) {
touchStartTime = (new Date()).getTime();
touchStartPos = evt.changedTouches[0];

// if we get a touch event, then stop listening for click
$elm.off('click', selectCells);
};

var touchEnd = function (evt) {
var touchEndTime = (new Date()).getTime();
var touchEndPos = evt.changedTouches[0];
var touchTime = touchEndTime - touchStartTime;
var touchXDiff = Math.abs(touchStartPos.clientX - touchEndPos.clientX)
var touchYDiff = Math.abs(touchStartPos.clientY - touchEndPos.clientY)

if (touchTime < touchTimeout) {

if (touchXDiff < touchPosDiff && touchYDiff < touchPosDiff) {
if (touchTime < touchPosDiff) {
// short touch
selectCells(evt);
selectCells(evt);
}
}

// don't re-enable the click handler for a little while - some devices generate both, and it will
Expand Down

0 comments on commit a537f0c

Please sign in to comment.