Last active
June 11, 2019 19:49
-
-
Save NilsonLima/f3649448e761a2f45629531c9746d72a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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