File tree Expand file tree Collapse file tree 1 file changed +19
-5
lines changed Expand file tree Collapse file tree 1 file changed +19
-5
lines changed Original file line number Diff line number Diff line change @@ -11,16 +11,30 @@ import browser from 'bowser'
1111export const contenteditable = typeof document . documentElement . contentEditable !== 'undefined'
1212
1313const parser = browser . getParser ( window . navigator . userAgent )
14- const browserName = parser . getBrowser ( )
1514const browserEngine = parser . getEngineName ( )
1615const webKit = browserEngine === 'WebKit'
1716
1817/**
19- * Check selectionchange event (currently supported in IE, Chrome, Firefox and Safari)
20- * Firefox supports it since version 52 (2017) so pretty sure this is fine.
18+ * Check selectionchange event (supported in IE, Chrome, Firefox and Safari)
19+ * Firefox supports it since version 52 (2017).
20+ * Opera has no support as of 2021.
2121 */
22- // not exactly feature detection... is it?
23- export const selectionchange = ! ( browserName === 'Opera' )
22+ const hasNativeSelectionchangeSupport = ( document ) => {
23+ const doc = document
24+ const osc = doc . onselectionchange
25+ if ( osc !== undefined ) {
26+ try {
27+ doc . onselectionchange = 0
28+ return doc . onselectionchange === null
29+ } catch ( e ) {
30+ } finally {
31+ doc . onselectionchange = osc
32+ }
33+ }
34+ return false
35+ }
36+
37+ export const selectionchange = hasNativeSelectionchangeSupport ( document )
2438
2539// See Keyboard.prototype.preventContenteditableBug for more information.
2640export const contenteditableSpanBug = ! ! webKit
You can’t perform that action at this time.
0 commit comments