Skip to content

Commit

Permalink
Merge pull request #989 from Tyriar/986_selection_exception
Browse files Browse the repository at this point in the history
Ensure mouse coordinates are always within rows/cols
  • Loading branch information
Tyriar authored Sep 14, 2017
2 parents 3d743e5 + 691ab2b commit 1f49879
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/utils/Mouse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
4 changes: 2 additions & 2 deletions src/utils/Mouse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 1f49879

Please sign in to comment.