0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 23:40:35 -05:00

Catch and log FF error getting selection.

This commit is contained in:
Neil Jenkins 2013-03-27 16:03:03 +11:00
parent 768f4420b9
commit 02d25f0ef5

View file

@ -163,6 +163,9 @@
lastSelection = sel.getRangeAt( 0 ).cloneRange(); lastSelection = sel.getRangeAt( 0 ).cloneRange();
var startContainer = lastSelection.startContainer, var startContainer = lastSelection.startContainer,
endContainer = lastSelection.endContainer; endContainer = lastSelection.endContainer;
// FF sometimes throws an error reading the isLeaf property. Let's
// catch and log it to see if we can find what's going on.
try {
// FF can return the selection as being inside an <img>. WTF? // FF can return the selection as being inside an <img>. WTF?
if ( startContainer && startContainer.isLeaf() ) { if ( startContainer && startContainer.isLeaf() ) {
lastSelection.setStartBefore( startContainer ); lastSelection.setStartBefore( startContainer );
@ -170,6 +173,13 @@
if ( endContainer && endContainer.isLeaf() ) { if ( endContainer && endContainer.isLeaf() ) {
lastSelection.setEndBefore( endContainer ); lastSelection.setEndBefore( endContainer );
} }
} catch ( error ) {
editor.didError({
name: 'Squire#getSelection error',
message: 'Starts: ' + startContainer.nodeName +
'\nEnds: ' + endContainer.nodeName
});
}
} }
return lastSelection; return lastSelection;
}; };