Fixed cursor positioning at the end of an iframe's text to work in more edge cases.
This commit is contained in:
parent
5e7cd17e82
commit
403ce9d305
|
@ -388,12 +388,17 @@ Editor.prototype.position_cursor = function ( click_position, div_range ) {
|
||||||
var selection = this.iframe.contentWindow.getSelection();
|
var selection = this.iframe.contentWindow.getSelection();
|
||||||
var last_node = this.document.body.lastChild;
|
var last_node = this.document.body.lastChild;
|
||||||
|
|
||||||
/// FIXME: sometimes positioning the cursor at the end puts it in a place where you can't type any characters
|
if ( selection.rangeCount > 0 )
|
||||||
if ( ( last_node.nodeValue == "\n" || last_node.tagName == "BR" ) && last_node.previousSibling )
|
var range = selection.getRangeAt( 0 );
|
||||||
|
else
|
||||||
|
var range = this.document.createRange();
|
||||||
|
|
||||||
|
while ( ( last_node.nodeValue == "\n" || last_node.tagName == "BR" ) && last_node.previousSibling )
|
||||||
last_node = last_node.previousSibling;
|
last_node = last_node.previousSibling;
|
||||||
|
|
||||||
selection.selectAllChildren( last_node );
|
range.selectNodeContents( last_node );
|
||||||
selection.collapseToEnd();
|
range.collapse( false );
|
||||||
|
selection.addRange( range );
|
||||||
} else if ( this.document.selection ) { // browsers such as IE
|
} else if ( this.document.selection ) { // browsers such as IE
|
||||||
var range = this.document.selection.createRange();
|
var range = this.document.selection.createRange();
|
||||||
range.move( "textedit" );
|
range.move( "textedit" );
|
||||||
|
|
Reference in New Issue