Merge pull request #989 from Tyriar/986_selection_exception

Ensure mouse coordinates are always within rows/cols
This commit is contained in:
Daniel Imms
2017-09-14 09:06:44 -07:00
committed by GitHub
2 changed files with 3 additions and 3 deletions
+1 -1
View File
@@ -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');
});
});
+2 -2
View File
@@ -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;
}