[draft-js] Allow a merged SelectionState to be passed to forceSelection (#45522)

* add override for merge on SelectionState

* prettier fix

* remove accidentally committed file
This commit is contained in:
Andy Katz 2020-07-07 13:08:04 -05:00 committed by GitHub
parent f1b6c1b820
commit a956dfd56d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -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);

View File

@ -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<keyof SelectionStateProperties, SelectionStateProperties[keyof SelectionStateProperties]>[]): SelectionState
merge(...iterables: Partial<SelectionStateProperties>[]): SelectionState
serialize(): string;
getAnchorKey(): string;
getAnchorOffset(): number;