suneditor
suneditor copied to clipboard
Get current Caret position
Hi @JiHong88 ,
It just a question, I wrote a function to get the current caret position (top, left). I am trying to trigger a modal when the user hits {{.
I inserted the below block of code in the onChange event
var range = core.getSelection().getRangeAt(0);
let text;
if (range.collapsed) {
text = range.startContainer.textContent.substring(0, range.startOffset);
}
if(text.slice(-2) === "{{") {
const {left, top} = range.getBoundingClientRect();
updatePosition(top, left)
}
is it the correct way to retrieve the caret position? Sometimes, I am getting the wrong position.
Thank you in Advance.
@gopal1996 Refer this code. https://github.com/JiHong88/SunEditor/blob/master/src/lib/core.js#L5722 This function is set position of the balloon toolbar.
it seems that the link no longer points to the proper text line - could you please provide a function name or s.th. similar?