Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

draft js insert text example

// get current editor state 
    const currentContent = editorState.getCurrentContent();

 // create new selection state where focus is at the end
    const blockMap = currentContent.getBlockMap();
    const key = blockMap.last().getKey();
    const length = blockMap.last().getLength();
    const selection = new SelectionState({
        anchorKey: key,
        anchorOffset: length,
        focusKey: key,
        focusOffset: length,
      });

   //insert text at the selection created above 
    const textWithInsert = Modifier.insertText(currentContent, selection, 'text to be inserted', null);
    const editorWithInsert = EditorState.push(editorState, textWithInsert, 'insert-characters');

    //also focuses cursor at the end of the editor 
    const newEditorState = EditorState.moveSelectionToEnd(editorWithInsert, textWithInsert.getSelectionAfter());
    setEditorState(newEditorState);
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery check if all elements hidden 
Javascript :: how to call mixin in vuex 
Javascript :: react multiple select dropdown 
Javascript :: React S3 Bucket 
Javascript :: fibbanacci sequence 
Javascript :: angular chart js legend position 
Javascript :: clock picker jquery 
Javascript :: _.extend 
Javascript :: reduce method in javascript 
Javascript :: conditional operator 
Javascript :: save js 
Javascript :: $[name] in jquery 
Javascript :: math module js 
Javascript :: form in react 
Javascript :: sort string mixed with numbers javascript 
Javascript :: JavaScript Object Accessors 
Javascript :: moment date format 
Javascript :: build react app 
Javascript :: could not decode base64 cloudinary 
Javascript :: json concat 
Javascript :: joining array of string 
Javascript :: multi filtering react 
Javascript :: what is the slice method in javascript 
Javascript :: how to get the current username with wscript 
Javascript :: what are built in objects in javascript 
Javascript :: decode jwt tokens 
Javascript :: sweetalert2 small icon 
Javascript :: hide screen links in drawerNavigation in react native 
Javascript :: Find Dubplicate In Array of Object 
Javascript :: inline styling react 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =