This repository has been archived by the owner on Feb 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Type selection object in editOnInput.
Summary: Recently I merged D20582792— it was a quick fix to a a huge problem that was causing thousands of exceptions for our users. It could've been prevented with better typing, but wasn't caught by flow because the type of the selection object was assumed to be null. Here I implement the type of the selection object, and in the process catch other elements that could be null and add safeguards to make our code more reliable. This are places where the previous implementation would've thrown an exception. Reviewed By: kedromelon Differential Revision: D20636236 fbshipit-source-id: 6e27040120256e3885bfdd2d9cbedf5e57988062
- Loading branch information
1 parent
97dd19b
commit 41beae1
Showing
2 changed files
with
36 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* (c) Facebook, Inc. and its affiliates. Confidential and proprietary. | ||
* | ||
* Types for things in the DOM used in Draft.js. These should eventaully be | ||
* added to the flow DOM lib itself. | ||
* | ||
* @emails oncall+draft_js | ||
* @flow strict | ||
* @format | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// https://developer.mozilla.org/en-US/docs/Web/API/Selection | ||
export type SelectionObject = {| | ||
/** | ||
* Returns the Node in which the selection begins. Can return null if | ||
* selection never existed in the document (e.g., an iframe that was | ||
* never clicked on). */ | ||
anchorNode: ?Node, | ||
anchorOffset: number, | ||
focusNode: ?Node, | ||
focusOffset: number, | ||
isCollapsed: boolean, | ||
rangeCount: number, | ||
type: string, | ||
// ...etc. This is a non-exhaustive definition. | ||
|}; |