File tree 1 file changed +19
-5
lines changed
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'
11
11
export const contenteditable = typeof document . documentElement . contentEditable !== 'undefined'
12
12
13
13
const parser = browser . getParser ( window . navigator . userAgent )
14
- const browserName = parser . getBrowser ( )
15
14
const browserEngine = parser . getEngineName ( )
16
15
const webKit = browserEngine === 'WebKit'
17
16
18
17
/**
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.
21
21
*/
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 )
24
38
25
39
// See Keyboard.prototype.preventContenteditableBug for more information.
26
40
export const contenteditableSpanBug = ! ! webKit
You can’t perform that action at this time.
0 commit comments