text at specific position in richtexteditor
How to add the text at specific cursor position in richtexteditor? any sample code? Need urgently Thanks,
Hi @NorthstarTech,
Can you elaborate on what you mean by "specific cursor position"? Is that the beginning/end of the selection? Or is the target position more dynamic? A code example showing what you have so far (obviously it's OK that it's not going to be completely functional since you're asking about how to add some functionality) or a more complete description of what you want would be helpful for me to assist.
From what I've seen the richtexteditor relies on browser contenteditable/selection APIs to insert content at specific positions/ranges, so I think you would want to start there. Check out the result function in the link action in the RichTextEditor object (line 40: https://github.com/artf/grapesjs/blob/688faaaa2a5be891545a45c086a735571d1fb67a/src/rich_text_editor/model/RichTextEditor.js). I think you're going to want to do something similar, but before calling rte.insertHTML(), you'll want to modify the currently selected range so that the content is inserted at the desired location. I think you can get access to the current selection/range through rte.selection().
Here's a few links that may be helpful: https://github.com/artf/grapesjs/wiki/API-Rich-Text-Editor#add https://developer.mozilla.org/en-US/docs/Web/API/Selection https://stackoverflow.com/questions/3771824/select-range-in-contenteditable-div
Thanks Ryan for the detailed explanation, by the way, I think this is the same as #111 so close as a duplication
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.