Skip to content

Commit a9ba92f

Browse files
authored
Merge pull request #8 from github/edge-fix
Disable Markdown quoting/copying for Microsoft Edge
2 parents 9cb0c6e + 9e78a99 commit a9ba92f

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

quote-selection.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import rangeToMarkdown from './markdown-parsing'
55
const containers = new WeakMap()
66
let installed = 0
77

8+
const edgeBrowser = /\bEdge\//.test(navigator.userAgent)
9+
810
type Subscription = {|
911
unsubscribe: () => void
1012
|}
@@ -19,10 +21,15 @@ export function subscribe(container: Element): Subscription {
1921
}
2022

2123
export function install(container: Element) {
24+
const firstInstall = installed === 0
2225
installed += containers.has(container) ? 0 : 1
2326
containers.set(container, 1)
24-
document.addEventListener('keydown', quoteSelection)
25-
container.addEventListener('copy', onCopy)
27+
if (firstInstall) {
28+
document.addEventListener('keydown', quoteSelection)
29+
}
30+
if (!edgeBrowser) {
31+
container.addEventListener('copy', onCopy)
32+
}
2633
}
2734

2835
export function uninstall(container: Element) {
@@ -31,7 +38,9 @@ export function uninstall(container: Element) {
3138
if (!installed) {
3239
document.removeEventListener('keydown', quoteSelection)
3340
}
34-
container.removeEventListener('copy', onCopy)
41+
if (!edgeBrowser) {
42+
container.removeEventListener('copy', onCopy)
43+
}
3544
}
3645

3746
function onCopy(event: ClipboardEvent) {
@@ -142,7 +151,7 @@ function extractQuote(text: string, range: Range, unwrap: boolean): ?Quote {
142151
if (!container) return
143152

144153
const markdownSelector = container.getAttribute('data-quote-markdown')
145-
if (markdownSelector != null) {
154+
if (markdownSelector != null && !edgeBrowser) {
146155
try {
147156
selectionText = selectFragment(rangeToMarkdown(range, markdownSelector, unwrap))
148157
.replace(/^\n+/, '')

0 commit comments

Comments
 (0)