From a956dfd56dded940e5eeeb10c2ee6072af455916 Mon Sep 17 00:00:00 2001 From: Andy Katz Date: Tue, 7 Jul 2020 13:08:04 -0500 Subject: [PATCH] [draft-js] Allow a merged SelectionState to be passed to forceSelection (#45522) * add override for merge on SelectionState * prettier fix * remove accidentally committed file --- types/draft-js/draft-js-tests.tsx | 5 +++++ types/draft-js/index.d.ts | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/types/draft-js/draft-js-tests.tsx b/types/draft-js/draft-js-tests.tsx index 952c8c213e..da438ee8a2 100644 --- a/types/draft-js/draft-js-tests.tsx +++ b/types/draft-js/draft-js-tests.tsx @@ -362,6 +362,11 @@ ReactDOM.render( ); const editorState = EditorState.createEmpty(); + +const selection = editorState.getSelection(); +const newSelection = selection.merge({ focusKey: '8ajs', focusOffset: 0, isBackward: true }); +EditorState.forceSelection(editorState, newSelection); + const contentState = editorState.getCurrentContent(); const entityMap = contentState.getEntityMap(); const rawContentState: RawDraftContentState = convertToRaw(contentState); diff --git a/types/draft-js/index.d.ts b/types/draft-js/index.d.ts index 71ff5e4eb3..4fbb6a44ea 100644 --- a/types/draft-js/index.d.ts +++ b/types/draft-js/index.d.ts @@ -852,9 +852,21 @@ declare namespace Draft { hasText(): boolean; } + interface SelectionStateProperties { + anchorKey: string + anchorOffset: number + focusKey: string + focusOffset: number + isBackward: boolean + hasFocus: boolean + } + class SelectionState extends Record { static createEmpty(key: string): SelectionState; + merge(...iterables: Immutable.Iterable[]): SelectionState + merge(...iterables: Partial[]): SelectionState + serialize(): string; getAnchorKey(): string; getAnchorOffset(): number;