Skip to content

Instantly share code, notes, and snippets.

@NilsonLima
Last active June 11, 2019 19:49
Show Gist options
  • Save NilsonLima/f3649448e761a2f45629531c9746d72a to your computer and use it in GitHub Desktop.
Save NilsonLima/f3649448e761a2f45629531c9746d72a to your computer and use it in GitHub Desktop.
handleReturn = (event: SyntheticKeyboardEvent<*>) => {
const { onSubmit } = this.props;
if (event.shiftKey) return "not-handled";
if (onSubmit) onSubmit();
return "handled";
};
clear = () => {
const { editorState: oldEditorState } = this.state;
const oldContentState: ContentState = oldEditorState.getCurrentContent();
const firstBlock: ContentBlock = oldContentState.getFirstBlock();
const lastBlock: ContentBlock = oldContentState.getLastBlock();
const selection: SelectionState = new SelectionState({
anchorKey: firstBlock.getKey(),
anchorOffset: 0,
focusKey: lastBlock.getKey(),
focusOffset: lastBlock.getLength(),
hasFocus: true
});
const contentState: ContentState = Modifier.removeRange(
oldContentState,
selection,
"backward"
);
const editorState: EditorState = EditorState.push(
oldEditorState,
contentState,
"remove-range"
);
this.setState({
editorState: EditorState.forceSelection(
editorState,
contentState.getSelectionAfter()
)
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment