Increasingly brittle, but this fixes the following bug:
* hit bold, type some text, hit space, start a link. this will not actually start a link and will just insert a space
This commit is contained in:
parent
a6fff8da31
commit
bcd1dcbcd9
|
@ -323,7 +323,29 @@ Editor.prototype.start_link = function () {
|
||||||
this.insert_html( " " );
|
this.insert_html( " " );
|
||||||
var range = selection.getRangeAt( 0 );
|
var range = selection.getRangeAt( 0 );
|
||||||
var container = range.startContainer;
|
var container = range.startContainer;
|
||||||
range.setStart( container, ( range.startOffset ? range.startOffset - 1 : 0 ) );
|
|
||||||
|
// if for some reason the inserted isn't in the container we expect it to be in, use
|
||||||
|
// the previous sibling container instead
|
||||||
|
if ( range.startOffset == 0 ) {
|
||||||
|
var previous = null;
|
||||||
|
for ( i in container.parentNode.childNodes ) {
|
||||||
|
var child = container.parentNode.childNodes[ i ];
|
||||||
|
|
||||||
|
if ( child == container ) {
|
||||||
|
container = previous;
|
||||||
|
// descend into the sibling container until a text node is found
|
||||||
|
while ( container.firstChild && container.firstChild.noteType != 3 )
|
||||||
|
container = container.firstChild;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
previous = child;
|
||||||
|
}
|
||||||
|
// assume the got subsumed into the end of the sibling container
|
||||||
|
range.setStart( container, container.nodeValue.length - 1 );
|
||||||
|
} else {
|
||||||
|
range.setStart( container, range.startOffset - 1 );
|
||||||
|
}
|
||||||
|
|
||||||
this.exec_command( "createLink", "/notes/new" );
|
this.exec_command( "createLink", "/notes/new" );
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user