Make SelectionManager more resilient

Fixes #809
This commit is contained in:
Daniel Imms
2017-07-21 05:45:53 -07:00
parent 18f3cc77e5
commit e56f710cd1
2 changed files with 34 additions and 8 deletions
+8
View File
@@ -37,7 +37,15 @@ export function getCoordsRelativeToElement(event: MouseEvent, element: HTMLEleme
* select that cell and the right half will select the next cell.
*/
export function getCoords(event: MouseEvent, rowContainer: HTMLElement, charMeasure: CharMeasure, colCount: number, rowCount: number, isSelection?: boolean): [number, number] {
// Coordinates cannot be measured if charMeasure has not been initialized
if (!charMeasure.width || !charMeasure.height) {
return null;
}
const coords = getCoordsRelativeToElement(event, rowContainer);
if (!coords) {
return null;
}
// Convert to cols/rows.
coords[0] = Math.ceil((coords[0] + (isSelection ? charMeasure.width / 2 : 0)) / charMeasure.width);