Skip to content

Commit 7c2dd66

Browse files
authored
Fix tooltip not to be displayed by long touch (#379)
* Fix tooltip not to be displayed by long touch * fix
1 parent 03a24aa commit 7c2dd66

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

packages/cheetah-grid/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cheetah-grid",
3-
"version": "1.7.8",
3+
"version": "1.7.9",
44
"description": "Cheetah Grid is a high performance grid engine that works on canvas",
55
"keywords": [
66
"spreadsheet",

packages/cheetah-grid/src/js/core/DrawGrid.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,13 +1341,22 @@ function _bindEvents(this: DrawGrid): void {
13411341
| null
13421342
| undefined = null;
13431343
let longTouchId: NodeJS.Timeout | null = null;
1344-
let touchStartIntervalId: NodeJS.Timeout | null = null;
1344+
let useTouch: { timeoutId?: NodeJS.Timeout } | null = null;
1345+
function useTouchStart() {
1346+
if (useTouch?.timeoutId != null) clearTimeout(useTouch.timeoutId);
1347+
useTouch = {};
1348+
}
1349+
function useTouchEnd() {
1350+
if (useTouch) {
1351+
if (useTouch.timeoutId != null) clearTimeout(useTouch.timeoutId);
1352+
useTouch.timeoutId = setTimeout(() => {
1353+
useTouch = null;
1354+
}, 350);
1355+
}
1356+
}
13451357
handler.on(element, "touchstart", (e) => {
13461358
// Since it is an environment where touch start can be used, it blocks mousemove that occurs after this.
1347-
if (touchStartIntervalId != null) clearTimeout(touchStartIntervalId);
1348-
touchStartIntervalId = setTimeout(() => {
1349-
touchStartIntervalId = null;
1350-
}, 350);
1359+
useTouchStart();
13511360

13521361
if (!doubleTapBefore) {
13531362
doubleTapBefore = getCellEventArgsSet(e).eventArgs;
@@ -1402,9 +1411,13 @@ function _bindEvents(this: DrawGrid): void {
14021411
longTouchId = null;
14031412
}
14041413
}
1405-
handler.on(element, "touchcancel", cancel);
1414+
handler.on(element, "touchcancel", (e) => {
1415+
cancel(e);
1416+
useTouchEnd();
1417+
});
14061418
handler.on(element, "touchmove", cancel);
14071419
handler.on(element, "touchend", (e) => {
1420+
useTouchEnd();
14081421
if (longTouchId) {
14091422
clearTimeout(longTouchId);
14101423
grid[_].cellSelector.select(e);
@@ -1469,7 +1482,7 @@ function _bindEvents(this: DrawGrid): void {
14691482
});
14701483

14711484
handler.on(element, "mousemove", (e) => {
1472-
if (touchStartIntervalId != null) {
1485+
if (useTouch) {
14731486
// Probably a mousemove event triggered by a touchstart. Therefore, this event is blocked.
14741487
return;
14751488
}

packages/vue-cheetah-grid/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-cheetah-grid",
3-
"version": "1.7.8",
3+
"version": "1.7.9",
44
"description": "Cheetah Grid for Vue.js",
55
"main": "lib/index.js",
66
"unpkg": "dist/vueCheetahGrid.js",

0 commit comments

Comments
 (0)