xdan / jodit

Jodit - Best WYSIWYG Editor for You
https://xdsoft.net/jodit/
MIT License
1.66k stars 350 forks source link

Issue on adding content from outside of editor #1116

Open PramodK2807 opened 5 months ago

PramodK2807 commented 5 months ago

Adding the content from the outside of editor (like, on button click), content is not added at the cursor position,

xdan commented 5 months ago

Please, show example please

PramodK2807 commented 5 months ago

`let editorRef; const editor = useRef(null);

const addSomeTextToEditor = () => { let textContainer = document.createElement("span"); textContainer.innerHTML = "add custom text to the editor on click"; editorRef.selection.insertNode(textContainer); };

{ editorRef = ref; }} ref={editor} name="content" tabIndex={1} onBlur={(newContent) => { setContent(newContent); // extractVariables(newContent); }} value={content} config={config} />
       <button onClick={addSomeTextToEditor }>Add Text </button>

`
this is working fine, but the text is added on start of content

xdan commented 4 months ago

When the click event occurs, the cursor leaves the editor. Try to handle pointerdown rather than click and do preventDefault() to avoid losing the cursor