Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Commit

Permalink
Type selection object in keyCommandBackspaceToStartOfLine.js
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mrkev authored and facebook-github-bot committed Apr 22, 2020
1 parent af67575 commit aa5c4a1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

'use strict';

import type {SelectionObject} from 'DraftDOMTypes';

const EditorState = require('EditorState');

const expandRangeToStartOfLine = require('expandRangeToStartOfLine');
Expand All @@ -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);

Expand Down
1 change: 1 addition & 0 deletions src/component/utils/DraftDOMTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ export type SelectionObject = {|
type: string,

removeAllRanges(): void,
getRangeAt: (index: number) => Range,
// ...etc. This is a non-exhaustive definition.
|};

0 comments on commit aa5c4a1

Please sign in to comment.