Last active
July 1, 2018 07:28
-
-
Save levvsha/e1d93eff1bc17ee1c20e7584f70355c6 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
| setLink() { | |
| // getting url from prompt dialogue | |
| const urlValue = prompt('Paste URL', ''); | |
| // getting current editor state | |
| const { editorState } = this.state; | |
| // getting current contentState | |
| const contentState = editorState.getCurrentContent(); | |
| // creating Entity | |
| const contentStateWithEntity = contentState.createEntity( | |
| 'LINK', | |
| 'SEGMENTED', | |
| { url: urlValue } | |
| ); | |
| const entityKey = contentStateWithEntity.getLastCreatedEntityKey(); | |
| // updating currentContent property in editorState | |
| const newEditorState = EditorState.set(editorState, {currentContent: contentStateWithEntity}); | |
| // generating and saving new editor state | |
| this.setState({ | |
| editorState: RichUtils.toggleLink( | |
| newEditorState, | |
| newEditorState.getSelection(), | |
| entityKey | |
| ) | |
| }, () => { | |
| setTimeout(() => this.focus(), 0); | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment