I'm facing a annoying problem. I'm working on a little RTE, and I'm now trying to move the caret at the end of an element.
Right now, here is the code I have (from this post How to move cursor to end of contenteditable entity) :
I have some custom functions to work on the range and the window. I'm nearly sure they are correct.
function(contentEditableElement){
var contentEditableElement = this.getFocusedElement().parentNode;
if(this.contentDoc.createRange)//Firefox, Chrome, Opera, Safari, IE 9+
{
range = this.contentDoc.createRange();//Create a range (a range is a like the selection but invisible)
range.selectNodeContents(contentEditableElement);//Select the entire contents of the element with the range
range.collapse(false);//collapse the range to the end point. false means collapse to end rather than the start
selection = this.win.getSelection();//get the selection object (allows you to change selection)
selection.removeAllRanges();//remove any selections already made
selection.addRange(range);//make the range you have just created the visible selection
}
else if(this.doc.selection)//IE 8 and lower
{
range = document.body.createTextRange();//Create a range (a range is a like the selection but invisible)
range.moveToElementText(contentEditableElement);//Select the entire contents of the element with the range
range.collapse(false);//collapse the range to the end point. false means collapse to end rather than the start
range.select();//Select the range (make it the visible selection
}
}
It works very well under FF and Opera...but in Chromium, the caret simply does not move.
Can you help me to find the right way ? Thanks
likeTHIS
) then I'm able to set the caret at the end of. If it's empty, then I cannot. It seems I'm gonna have to do some kind of buffering.
– nioKi Jun 12 '12 at 22:50