From aa5c4a19c927d1023630963b0db8fa861c78e161 Mon Sep 17 00:00:00 2001 From: Kevin Chavez Date: Wed, 22 Apr 2020 13:05:50 -0700 Subject: [PATCH] Type selection object in keyCommandBackspaceToStartOfLine.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Typing more things with the SelectionObject type. No change in behaviour. Added a comment for something I noticed— can be revisited later. Reviewed By: claudiopro Differential Revision: D21006848 fbshipit-source-id: f6337b11d48ca03974e65d7db5bd069a9f64523f --- .../edit/commands/keyCommandBackspaceToStartOfLine.js | 7 ++++++- src/component/utils/DraftDOMTypes.js | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) 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. |};