Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- setLink() {
- // getting url from prompt dialogue
- const urlValue = prompt('Введите ссылку', '');
- // 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);
- });
- }
Add Comment
Please, Sign In to add comment