mirror of
https://github.com/fastmail/Squire.git
synced 2024-12-22 15:23:29 -05:00
Catch and log FF error getting selection.
This commit is contained in:
parent
768f4420b9
commit
02d25f0ef5
1 changed files with 16 additions and 6 deletions
|
@ -163,12 +163,22 @@
|
||||||
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 can return the selection as being inside an <img>. WTF?
|
// FF sometimes throws an error reading the isLeaf property. Let's
|
||||||
if ( startContainer && startContainer.isLeaf() ) {
|
// catch and log it to see if we can find what's going on.
|
||||||
lastSelection.setStartBefore( startContainer );
|
try {
|
||||||
}
|
// FF can return the selection as being inside an <img>. WTF?
|
||||||
if ( endContainer && endContainer.isLeaf() ) {
|
if ( startContainer && startContainer.isLeaf() ) {
|
||||||
lastSelection.setEndBefore( endContainer );
|
lastSelection.setStartBefore( startContainer );
|
||||||
|
}
|
||||||
|
if ( endContainer && endContainer.isLeaf() ) {
|
||||||
|
lastSelection.setEndBefore( endContainer );
|
||||||
|
}
|
||||||
|
} catch ( error ) {
|
||||||
|
editor.didError({
|
||||||
|
name: 'Squire#getSelection error',
|
||||||
|
message: 'Starts: ' + startContainer.nodeName +
|
||||||
|
'\nEnds: ' + endContainer.nodeName
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return lastSelection;
|
return lastSelection;
|
||||||
|
|
Loading…
Reference in a new issue