-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
351 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Rect } from 'roosterjs-editor-types'; | ||
|
||
/** | ||
* A ClientRect of all 0 is possible. i.e. chrome returns a ClientRect of 0 when the cursor is on an empty p | ||
* We validate that and only return a rect when the passed in ClientRect is valid | ||
*/ | ||
export default function normalizeRect(clientRect: ClientRect): Rect { | ||
let { left, right, top, bottom } = | ||
clientRect || <ClientRect>{ left: 0, right: 0, top: 0, bottom: 0 }; | ||
return left + right + top + bottom > 0 | ||
? { | ||
left: Math.round(left), | ||
right: Math.round(right), | ||
top: Math.round(top), | ||
bottom: Math.round(bottom), | ||
} | ||
: null; | ||
} |
Oops, something went wrong.