0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-31 11:54:03 -05:00

Fix IE returns null for getSelection if never focussed.

This commit is contained in:
Neil Jenkins 2012-08-09 12:00:55 +10:00
parent 52a10d463c
commit f9974ed7d9
4 changed files with 11 additions and 8 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -167,7 +167,7 @@
return lastSelection; return lastSelection;
}; };
// IE9 loses selection state of iframe on blur, so make sure we // IE loses selection state of iframe on blur, so make sure we
// cache it just before it loses focus. // cache it just before it loses focus.
if ( losesSelectionOnBlur ) { if ( losesSelectionOnBlur ) {
win.addEventListener( 'beforedeactivate', getSelection, true ); win.addEventListener( 'beforedeactivate', getSelection, true );
@ -1761,10 +1761,13 @@
var range = createRange( body.firstChild, 0 ); var range = createRange( body.firstChild, 0 );
recordUndoState( range ); recordUndoState( range );
getRangeAndRemoveBookmark( range ); getRangeAndRemoveBookmark( range );
// IE8 will also set focus when selecting text. // IE will also set focus when selecting text so don't use
// It doesn't make any difference since it doesn't // setSelection. Instead, just store it in lastSelection, so if
// maintain selection when not focussed anyway. // anything calls getSelection before first focus, we have a range
if ( !isIE8 ) { // to return.
if ( losesSelectionOnBlur ) {
lastSelection = range;
} else {
setSelection( range ); setSelection( range );
} }
updatePath( range, true ); updatePath( range, true );

View file

@ -452,7 +452,7 @@ var toTextRange = function ( range ) {
}; };
var selection = { var selection = {
rangeCount: 1, rangeCount: 0,
getRangeAt: function ( index ) { getRangeAt: function ( index ) {
if ( index !== 0 ) { return undefined; } if ( index !== 0 ) { return undefined; }
var sel = document.selection.createRange(); var sel = document.selection.createRange();