File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -24,22 +24,30 @@ export default class SelectionWatcher {
2424
2525 /**
2626 * Updates the internal selection pointer to the current rangy selection.
27+ * Returns true if no exception occured.
2728 */
2829 syncSelection ( ) {
29- this . rangySelection = rangy . getSelection ( this . win )
30+ // it is possible that rangy has a problem with the nativeSelection
31+ try {
32+ this . rangySelection = rangy . getSelection ( this . win )
33+ } catch ( err ) {
34+ return false
35+ }
36+
37+ return true
3038 }
3139
3240 /**
3341 * Return a RangeContainer if the current selection is within an editable
3442 * otherwise return an empty RangeContainer
3543 */
3644 getRangeContainer ( ) {
37- this . syncSelection ( )
45+ const successfulSync = this . syncSelection ( )
3846
3947 // rangeCount is 0 or 1 in all browsers except firefox
4048 // firefox can work with multiple ranges
4149 // (on a mac hold down the command key to select multiple ranges)
42- if ( this . rangySelection . rangeCount ) {
50+ if ( this . rangySelection . rangeCount && successfulSync ) {
4351 const range = this . rangySelection . getRangeAt ( 0 )
4452 const hostNode = parser . getHost ( range . commonAncestorContainer )
4553 if ( hostNode ) return new RangeContainer ( hostNode , range )
You can’t perform that action at this time.
0 commit comments