We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4ef99a7 commit 72da9f9Copy full SHA for 72da9f9
src/modifiers/addImage.js
@@ -0,0 +1,18 @@
1
+import { EditorState, AtomicBlockUtils } from 'draft-js';
2
+
3
+export default (editorState, entityType, data = {}) => {
4
+ const contentState = editorState.getCurrentContent();
5
+ const contentStateWithEntity = contentState.createEntity(entityType, 'IMMUTABLE', data);
6
+ const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
7
8
+ const newEditorState = AtomicBlockUtils.insertAtomicBlock(
9
+ editorState,
10
+ entityKey,
11
+ ' '
12
+ );
13
14
+ return EditorState.forceSelection(
15
+ newEditorState,
16
+ newEditorState.getCurrentContent().getSelectionAfter()
17
18
+};
0 commit comments