Skip to content

Commit bb1f3dc

Browse files
fixed the copy code feature in the browser
1 parent 196d73b commit bb1f3dc

14 files changed

+12
-28
lines changed

browser/js/code_editor.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,22 @@ const CopyCode = {
2424
},
2525
methods: {
2626
selectContent() {
27-
let range, selection;
2827
let textArea = this.$refs.textarea;
29-
if (!/Chrome/.test(navigator.userAgent)) {
28+
// modern browser support (using the clipboard API)
29+
if (navigator && navigator.clipboard)
30+
return navigator.clipboard.writeText(textArea.value);
31+
else {
32+
// older browser support
33+
let range, selection;
34+
textArea.focus();
35+
textArea.select();
3036
range = document.createRange();
3137
range.selectNodeContents(textArea);
3238
selection = window.getSelection();
3339
selection.removeAllRanges();
3440
selection.addRange(range);
3541
textArea.setSelectionRange(0, textArea.value.length);
36-
} else {
37-
textArea.select();
38-
}
39-
if (document.execCommand("copy") == true) {
4042
document.execCommand("copy");
41-
} else {
42-
navigator.clipboard.writeText(textArea.value);
4343
}
4444
},
4545
copy(event) {

browser/js/dist/code_editor.prod.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/css/app.d4970746.css

Lines changed: 0 additions & 9 deletions
This file was deleted.

dist/favicon.ico

-16.6 KB
Binary file not shown.
-44.3 KB
Binary file not shown.
-32.6 KB
Binary file not shown.

dist/index.html

Lines changed: 0 additions & 1 deletion
This file was deleted.

dist/js/app.f5c98d01.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

dist/js/app.f5c98d01.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

dist/js/chunk-vendors.27c4acf8.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)