Guest User

Untitled

a guest
Jun 25th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. setLink() {
  2. // getting url from prompt dialogue
  3. const urlValue = prompt('Введите ссылку', '');
  4. // getting current editor state
  5. const { editorState } = this.state;
  6. // getting current contentState
  7. const contentState = editorState.getCurrentContent();
  8. // creating Entity
  9. const contentStateWithEntity = contentState.createEntity(
  10. 'LINK',
  11. 'SEGMENTED',
  12. { url: urlValue }
  13. );
  14. const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
  15. // updating currentContent property in editorState
  16. const newEditorState = EditorState.set(editorState, {currentContent: contentStateWithEntity});
  17.  
  18. // generating and saving new editor state
  19. this.setState({
  20. editorState: RichUtils.toggleLink(
  21. newEditorState,
  22. newEditorState.getSelection(),
  23. entityKey
  24. )
  25. }, () => {
  26. setTimeout(() => this.focus(), 0);
  27. });
  28. }
Add Comment
Please, Sign In to add comment