draft-js-modifiers
Version:
Modular state modifiers for Draft.js
11 lines (9 loc) • 550 B
JavaScript
import { EditorState, Modifier } from 'draft-js';
var insertText = function insertText(editorState, text) {
var entity = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var selection = editorState.getSelection();
var content = editorState.getCurrentContent();
var newContent = Modifier[selection.isCollapsed() ? 'insertText' : 'replaceText'](content, selection, text, editorState.getCurrentInlineStyle(), entity);
return EditorState.push(editorState, newContent, 'insert-fragment');
};
export default insertText;