mirror of
https://github.com/fastmail/Squire.git
synced 2024-12-22 15:23:29 -05:00
Make editor.insertElement support block elements.
This commit is contained in:
parent
af1720282c
commit
e1bae30a16
3 changed files with 65 additions and 9 deletions
|
@ -1388,10 +1388,38 @@ var setHTML = function ( html ) {
|
|||
var insertElement = function ( el, range ) {
|
||||
if ( !range ) { range = getSelection(); }
|
||||
range.collapse( true );
|
||||
range._insertNode( el );
|
||||
range.setStartAfter( el );
|
||||
setSelection( range );
|
||||
updatePath( range );
|
||||
if ( isInline( el ) ) {
|
||||
range._insertNode( el );
|
||||
range.setStartAfter( el );
|
||||
} else {
|
||||
// Get containing block node.
|
||||
var splitNode = range.getStartBlock() || body,
|
||||
parent, nodeAfterSplit;
|
||||
// While at end of container node, move up DOM tree.
|
||||
while ( splitNode !== body && !splitNode.nextSibling ) {
|
||||
splitNode = splitNode.parentNode;
|
||||
}
|
||||
// If in the middle of a container node, split up to body.
|
||||
if ( splitNode !== body ) {
|
||||
parent = splitNode.parentNode;
|
||||
nodeAfterSplit = split( parent, splitNode.nextSibling, body );
|
||||
}
|
||||
if ( nodeAfterSplit ) {
|
||||
body.insertBefore( el, nodeAfterSplit );
|
||||
range.setStart( nodeAfterSplit, 0 );
|
||||
range.setStart( nodeAfterSplit, 0 );
|
||||
range.moveBoundariesDownTree();
|
||||
} else {
|
||||
body.appendChild( el );
|
||||
// Insert blank line below block.
|
||||
body.appendChild( fixCursor( createElement( 'div' ) ) );
|
||||
range.setStart( el, 0 );
|
||||
range.setEnd( el, 0 );
|
||||
}
|
||||
focus();
|
||||
setSelection( range );
|
||||
updatePath( range );
|
||||
}
|
||||
};
|
||||
|
||||
// --- Bookmarking ---
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -307,10 +307,38 @@ var setHTML = function ( html ) {
|
|||
var insertElement = function ( el, range ) {
|
||||
if ( !range ) { range = getSelection(); }
|
||||
range.collapse( true );
|
||||
range._insertNode( el );
|
||||
range.setStartAfter( el );
|
||||
setSelection( range );
|
||||
updatePath( range );
|
||||
if ( isInline( el ) ) {
|
||||
range._insertNode( el );
|
||||
range.setStartAfter( el );
|
||||
} else {
|
||||
// Get containing block node.
|
||||
var splitNode = range.getStartBlock() || body,
|
||||
parent, nodeAfterSplit;
|
||||
// While at end of container node, move up DOM tree.
|
||||
while ( splitNode !== body && !splitNode.nextSibling ) {
|
||||
splitNode = splitNode.parentNode;
|
||||
}
|
||||
// If in the middle of a container node, split up to body.
|
||||
if ( splitNode !== body ) {
|
||||
parent = splitNode.parentNode;
|
||||
nodeAfterSplit = split( parent, splitNode.nextSibling, body );
|
||||
}
|
||||
if ( nodeAfterSplit ) {
|
||||
body.insertBefore( el, nodeAfterSplit );
|
||||
range.setStart( nodeAfterSplit, 0 );
|
||||
range.setStart( nodeAfterSplit, 0 );
|
||||
range.moveBoundariesDownTree();
|
||||
} else {
|
||||
body.appendChild( el );
|
||||
// Insert blank line below block.
|
||||
body.appendChild( fixCursor( createElement( 'div' ) ) );
|
||||
range.setStart( el, 0 );
|
||||
range.setEnd( el, 0 );
|
||||
}
|
||||
focus();
|
||||
setSelection( range );
|
||||
updatePath( range );
|
||||
}
|
||||
};
|
||||
|
||||
// --- Bookmarking ---
|
||||
|
|
Loading…
Reference in a new issue