From a52b9feeea7d3ba877b30f1aa1601ed41317d66c Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Wed, 13 Sep 2017 14:03:40 -0700 Subject: [PATCH 1/2] Ensure mouse coordinates are always within rows/cols Fixes #986 --- src/utils/Mouse.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/Mouse.ts b/src/utils/Mouse.ts index aef76d5ba..7bc39b7fc 100644 --- a/src/utils/Mouse.ts +++ b/src/utils/Mouse.ts @@ -53,8 +53,8 @@ export function getCoords(event: {pageX: number, pageY: number}, element: HTMLEl coords[1] = Math.ceil(coords[1] / Math.ceil(charMeasure.height * lineHeight)); // Ensure coordinates are within the terminal viewport. - coords[0] = Math.min(Math.max(coords[0], 1), colCount + 1); - coords[1] = Math.min(Math.max(coords[1], 1), rowCount + 1); + coords[0] = Math.min(Math.max(coords[0], 1), colCount); + coords[1] = Math.min(Math.max(coords[1], 1), rowCount); return coords; } From 0cf9f1d5364d93b3bca8ed1eb5d9942b902a6de7 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Thu, 14 Sep 2017 09:05:50 -0700 Subject: [PATCH 2/2] Fix tests --- src/utils/Mouse.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/Mouse.test.ts b/src/utils/Mouse.test.ts index 4163263be..b96dd68ac 100644 --- a/src/utils/Mouse.test.ts +++ b/src/utils/Mouse.test.ts @@ -58,6 +58,6 @@ describe('getCoords', () => { assert.deepEqual(coords, [1, 1]); // Event are double the cols/rows coords = getCoords({ pageX: CHAR_WIDTH * 20, pageY: CHAR_HEIGHT * 20 }, document.createElement('div'), charMeasure, 1, 10, 10); - assert.deepEqual(coords, [11, 11], 'coordinates should never come back as larger than the terminal'); + assert.deepEqual(coords, [10, 10], 'coordinates should never come back as larger than the terminal'); }); });