Skip to content

Commit 260bd8c

Browse files
committed
refactor onCopyDelta
1 parent 1d662ee commit 260bd8c

File tree

2 files changed

+4
-21
lines changed

2 files changed

+4
-21
lines changed

src/js/bundle/jsdiff-panel.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.

src/js/view/panel.vue

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -135,20 +135,9 @@ const onToggleUnchanged = () => {
135135
}
136136
};
137137
138-
const onCopyDelta = () => {
139-
document.addEventListener('copy', $_onDocumentCopy);
140-
document.execCommand('copy', false);
141-
document.removeEventListener('copy', $_onDocumentCopy);
142-
143-
// modern alternative, but don't have permission [?]
144-
// navigator.clipboard.writeText(sDiff).then(
145-
// () => {
146-
// console.log('clipboard successfully set');
147-
// },
148-
// (e) => {
149-
// console.error('clipboard write failed', e);
150-
// }
151-
// );
138+
const onCopyDelta = async () => {
139+
const sDiff = JSON.stringify(deltaObj.value, null, 2);
140+
await navigator.clipboard.writeText(sDiff);
152141
};
153142
154143
function $_onRuntimeMessage(req) {
@@ -162,12 +151,6 @@ function $_onRuntimeMessage(req) {
162151
}
163152
}
164153
165-
function $_onDocumentCopy(e: ClipboardEvent) {
166-
const sDiff = JSON.stringify(deltaObj.value, null, 2);
167-
e.clipboardData?.setData('text', sDiff);
168-
e.preventDefault();
169-
}
170-
171154
function $_restartLastUpdated() {
172155
window.clearInterval(timer);
173156
timer = window.setInterval(() => {

0 commit comments

Comments
 (0)