mirror of
https://github.com/fastmail/Squire.git
synced 2025-01-03 05:00:13 -05:00
Use default block settings when fixCursor called on body
This commit is contained in:
parent
61d5004373
commit
3c8eaa1fcc
4 changed files with 46 additions and 32 deletions
|
@ -291,12 +291,14 @@ function fixCursor ( node ) {
|
||||||
// cursor to appear.
|
// cursor to appear.
|
||||||
var doc = node.ownerDocument,
|
var doc = node.ownerDocument,
|
||||||
root = node,
|
root = node,
|
||||||
fixer, child,
|
fixer, child, instance;
|
||||||
l, instance;
|
|
||||||
|
|
||||||
if ( node.nodeName === 'BODY' ) {
|
if ( node.nodeName === 'BODY' ) {
|
||||||
if ( !( child = node.firstChild ) || child.nodeName === 'BR' ) {
|
if ( !( child = node.firstChild ) || child.nodeName === 'BR' ) {
|
||||||
fixer = doc.createElement( 'DIV' );
|
instance = getSquireInstance( doc );
|
||||||
|
fixer = instance ?
|
||||||
|
instance.createDefaultBlock() :
|
||||||
|
createElement( doc, 'DIV' );
|
||||||
if ( child ) {
|
if ( child ) {
|
||||||
node.replaceChild( fixer, child );
|
node.replaceChild( fixer, child );
|
||||||
}
|
}
|
||||||
|
@ -318,14 +320,7 @@ function fixCursor ( node ) {
|
||||||
if ( !child ) {
|
if ( !child ) {
|
||||||
if ( cantFocusEmptyTextNodes ) {
|
if ( cantFocusEmptyTextNodes ) {
|
||||||
fixer = doc.createTextNode( ZWS );
|
fixer = doc.createTextNode( ZWS );
|
||||||
// Find the relevant Squire instance and notify
|
getSquireInstance( doc )._didAddZWS();
|
||||||
l = instances.length;
|
|
||||||
while ( l-- ) {
|
|
||||||
instance = instances[l];
|
|
||||||
if ( instance._doc === doc ) {
|
|
||||||
instance._didAddZWS();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
fixer = doc.createTextNode( '' );
|
fixer = doc.createTextNode( '' );
|
||||||
}
|
}
|
||||||
|
@ -351,7 +346,7 @@ function fixCursor ( node ) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( !node.querySelector( 'BR' ) ) {
|
else if ( !node.querySelector( 'BR' ) ) {
|
||||||
fixer = doc.createElement( 'BR' );
|
fixer = createElement( doc, 'BR' );
|
||||||
while ( ( child = node.lastElementChild ) && !isInline( child ) ) {
|
while ( ( child = node.lastElementChild ) && !isInline( child ) ) {
|
||||||
node = child;
|
node = child;
|
||||||
}
|
}
|
||||||
|
@ -566,7 +561,7 @@ function mergeContainers ( node ) {
|
||||||
if ( prev && areAlike( prev, node ) ) {
|
if ( prev && areAlike( prev, node ) ) {
|
||||||
if ( !isContainer( prev ) ) {
|
if ( !isContainer( prev ) ) {
|
||||||
if ( isListItem ) {
|
if ( isListItem ) {
|
||||||
block = doc.createElement( 'DIV' );
|
block = createElement( doc, 'DIV' );
|
||||||
block.appendChild( empty( prev ) );
|
block.appendChild( empty( prev ) );
|
||||||
prev.appendChild( block );
|
prev.appendChild( block );
|
||||||
} else {
|
} else {
|
||||||
|
@ -583,7 +578,7 @@ function mergeContainers ( node ) {
|
||||||
mergeContainers( first );
|
mergeContainers( first );
|
||||||
}
|
}
|
||||||
} else if ( isListItem ) {
|
} else if ( isListItem ) {
|
||||||
prev = doc.createElement( 'DIV' );
|
prev = createElement( doc, 'DIV' );
|
||||||
node.insertBefore( prev, first );
|
node.insertBefore( prev, first );
|
||||||
fixCursor( prev );
|
fixCursor( prev );
|
||||||
}
|
}
|
||||||
|
@ -810,7 +805,7 @@ var insertTreeFragmentIntoRange = function ( range, frag ) {
|
||||||
deleteContentsOfRange( range );
|
deleteContentsOfRange( range );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move range down into text ndoes
|
// Move range down into text nodes
|
||||||
moveRangeBoundariesDownTree( range );
|
moveRangeBoundariesDownTree( range );
|
||||||
|
|
||||||
// If inline, just insert at the current position.
|
// If inline, just insert at the current position.
|
||||||
|
@ -1097,6 +1092,18 @@ var expandRangeToBlockBoundaries = function ( range ) {
|
||||||
|
|
||||||
var instances = [];
|
var instances = [];
|
||||||
|
|
||||||
|
function getSquireInstance ( doc ) {
|
||||||
|
var l = instances.length,
|
||||||
|
instance;
|
||||||
|
while ( l-- ) {
|
||||||
|
instance = instances[l];
|
||||||
|
if ( instance._doc === doc ) {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
function Squire ( doc ) {
|
function Squire ( doc ) {
|
||||||
var win = doc.defaultView;
|
var win = doc.defaultView;
|
||||||
var body = doc.body;
|
var body = doc.body;
|
||||||
|
@ -2213,7 +2220,7 @@ var addLinks = function ( frag ) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var allowedBlock = /^(?:A(?:DDRESS|RTICLE|SIDE)|BLOCKQUOTE|CAPTION|D(?:[DLT]|IV)|F(?:IGURE|OOTER)|H[1-6]|HEADER|L(?:ABEL|EGEND|I)|O(?:L|UTPUT)|P(?:RE)?|SECTION|T(?:ABLE|BODY|D|FOOT|H|HEAD|R)|UL)$/;
|
var allowedBlock = /^(?:A(?:DDRESS|RTICLE|SIDE|UDIO)|BLOCKQUOTE|CAPTION|D(?:[DLT]|IV)|F(?:IGURE|OOTER)|H[1-6]|HEADER|L(?:ABEL|EGEND|I)|O(?:L|UTPUT)|P(?:RE)?|SECTION|T(?:ABLE|BODY|D|FOOT|H|HEAD|R)|UL)$/;
|
||||||
|
|
||||||
var fontSizes = {
|
var fontSizes = {
|
||||||
1: 10,
|
1: 10,
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -2,6 +2,18 @@
|
||||||
|
|
||||||
var instances = [];
|
var instances = [];
|
||||||
|
|
||||||
|
function getSquireInstance ( doc ) {
|
||||||
|
var l = instances.length,
|
||||||
|
instance;
|
||||||
|
while ( l-- ) {
|
||||||
|
instance = instances[l];
|
||||||
|
if ( instance._doc === doc ) {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
function Squire ( doc ) {
|
function Squire ( doc ) {
|
||||||
var win = doc.defaultView;
|
var win = doc.defaultView;
|
||||||
var body = doc.body;
|
var body = doc.body;
|
||||||
|
|
|
@ -160,12 +160,14 @@ function fixCursor ( node ) {
|
||||||
// cursor to appear.
|
// cursor to appear.
|
||||||
var doc = node.ownerDocument,
|
var doc = node.ownerDocument,
|
||||||
root = node,
|
root = node,
|
||||||
fixer, child,
|
fixer, child, instance;
|
||||||
l, instance;
|
|
||||||
|
|
||||||
if ( node.nodeName === 'BODY' ) {
|
if ( node.nodeName === 'BODY' ) {
|
||||||
if ( !( child = node.firstChild ) || child.nodeName === 'BR' ) {
|
if ( !( child = node.firstChild ) || child.nodeName === 'BR' ) {
|
||||||
fixer = doc.createElement( 'DIV' );
|
instance = getSquireInstance( doc );
|
||||||
|
fixer = instance ?
|
||||||
|
instance.createDefaultBlock() :
|
||||||
|
createElement( doc, 'DIV' );
|
||||||
if ( child ) {
|
if ( child ) {
|
||||||
node.replaceChild( fixer, child );
|
node.replaceChild( fixer, child );
|
||||||
}
|
}
|
||||||
|
@ -187,14 +189,7 @@ function fixCursor ( node ) {
|
||||||
if ( !child ) {
|
if ( !child ) {
|
||||||
if ( cantFocusEmptyTextNodes ) {
|
if ( cantFocusEmptyTextNodes ) {
|
||||||
fixer = doc.createTextNode( ZWS );
|
fixer = doc.createTextNode( ZWS );
|
||||||
// Find the relevant Squire instance and notify
|
getSquireInstance( doc )._didAddZWS();
|
||||||
l = instances.length;
|
|
||||||
while ( l-- ) {
|
|
||||||
instance = instances[l];
|
|
||||||
if ( instance._doc === doc ) {
|
|
||||||
instance._didAddZWS();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
fixer = doc.createTextNode( '' );
|
fixer = doc.createTextNode( '' );
|
||||||
}
|
}
|
||||||
|
@ -220,7 +215,7 @@ function fixCursor ( node ) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( !node.querySelector( 'BR' ) ) {
|
else if ( !node.querySelector( 'BR' ) ) {
|
||||||
fixer = doc.createElement( 'BR' );
|
fixer = createElement( doc, 'BR' );
|
||||||
while ( ( child = node.lastElementChild ) && !isInline( child ) ) {
|
while ( ( child = node.lastElementChild ) && !isInline( child ) ) {
|
||||||
node = child;
|
node = child;
|
||||||
}
|
}
|
||||||
|
@ -435,7 +430,7 @@ function mergeContainers ( node ) {
|
||||||
if ( prev && areAlike( prev, node ) ) {
|
if ( prev && areAlike( prev, node ) ) {
|
||||||
if ( !isContainer( prev ) ) {
|
if ( !isContainer( prev ) ) {
|
||||||
if ( isListItem ) {
|
if ( isListItem ) {
|
||||||
block = doc.createElement( 'DIV' );
|
block = createElement( doc, 'DIV' );
|
||||||
block.appendChild( empty( prev ) );
|
block.appendChild( empty( prev ) );
|
||||||
prev.appendChild( block );
|
prev.appendChild( block );
|
||||||
} else {
|
} else {
|
||||||
|
@ -452,7 +447,7 @@ function mergeContainers ( node ) {
|
||||||
mergeContainers( first );
|
mergeContainers( first );
|
||||||
}
|
}
|
||||||
} else if ( isListItem ) {
|
} else if ( isListItem ) {
|
||||||
prev = doc.createElement( 'DIV' );
|
prev = createElement( doc, 'DIV' );
|
||||||
node.insertBefore( prev, first );
|
node.insertBefore( prev, first );
|
||||||
fixCursor( prev );
|
fixCursor( prev );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue