diff --git a/src/component/handlers/edit/commands/keyCommandBackspaceToStartOfLine.js b/src/component/handlers/edit/commands/keyCommandBackspaceToStartOfLine.js index f2b418860b..af14473290 100644 --- a/src/component/handlers/edit/commands/keyCommandBackspaceToStartOfLine.js +++ b/src/component/handlers/edit/commands/keyCommandBackspaceToStartOfLine.js @@ -11,6 +11,8 @@ 'use strict'; +import type {SelectionObject} from 'DraftDOMTypes'; + const EditorState = require('EditorState'); const expandRangeToStartOfLine = require('expandRangeToStartOfLine'); @@ -30,7 +32,10 @@ function keyCommandBackspaceToStartOfLine( return moveSelectionBackward(strategyState, 1); } const {ownerDocument} = e.currentTarget; - const domSelection = ownerDocument.defaultView.getSelection(); + const domSelection: SelectionObject = ownerDocument.defaultView.getSelection(); + // TODO(T65805998): Noticed this while flowifiying: this could throw if nothing is + // selected. Not doing it now to keep my flowification diff from altering + // behaviour, but we should be safe and handle that case eventually. let range = domSelection.getRangeAt(0); range = expandRangeToStartOfLine(range); diff --git a/src/component/utils/DraftDOMTypes.js b/src/component/utils/DraftDOMTypes.js index 563aea5f68..0d7a3de6b2 100644 --- a/src/component/utils/DraftDOMTypes.js +++ b/src/component/utils/DraftDOMTypes.js @@ -26,5 +26,6 @@ export type SelectionObject = {| type: string, removeAllRanges(): void, + getRangeAt: (index: number) => Range, // ...etc. This is a non-exhaustive definition. |};