text at specific position in richtexteditor
Question
How to add the text at specific cursor position in richtexteditor? any sample code? Need urgently Thanks,
Answers (3)
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.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1999
Trait extends
Hi, I need to extends the video type, just to add a new trait/property: muted There is any documentation that can tell me how can i extend...
Issue #1403
how to build minified Css?
hi @artf Can You please explain me how can i build css from style section. Everytime when i run "Npm run build".Code build in min js only s...
Issue #1931
[Question]: How to insert image inside the link?
Hi @artf , How can I insert image inside the link? Please share your ideas what I need to do. If I need to create any custom component, ple...
Issue #1527
How to add countdown/navigation event in undo/redo
Hello @artf, How can we add any changes/events in undo/redo Manager like when we drag element like navigation or countdown. Hope for positi...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.