Open Richard-Dufour opened 1 year ago
This seems to work but is there a webfashionist/RichText way that would be more appropriate?
function InsertAtCursor(textToAdd) { console.log("textToAdd: ", textToAdd);
// These 4 lines is what actually inserts the text into the editor
let selection = window.getSelection();
let range = selection.getRangeAt(0);
let newNode = document.createTextNode(textToAdd);
range.insertNode(newNode);
}
Hi @Richard-Dufour
thank you for your question and code snippet.
There are similar functions within the code as of now, but none to add a custom text at the current caret position. What exactly is your use case for it?
Just that, I need to be able to insert some text at the current caret position (where the mouse is currently located).
That code snippet work, but I wanted to know if there was a better way to do this.
How can I insert text at the current cursor/caret position?