diff --git a/src/utils/copy.ts b/src/utils/copy.ts new file mode 100644 index 0000000000..6fd32d8b7a --- /dev/null +++ b/src/utils/copy.ts @@ -0,0 +1,18 @@ +export function copyToClip(text: string) { + return new Promise((resolve, reject) => { + try { + const input: HTMLTextAreaElement = document.createElement('textarea') + input.setAttribute('readonly', 'readonly') + input.value = text + document.body.appendChild(input) + input.select() + if (document.execCommand('copy')) + document.execCommand('copy') + document.body.removeChild(input) + resolve(text) + } + catch (error) { + reject(error) + } + }) +} diff --git a/src/views/chat/components/Message/Text.vue b/src/views/chat/components/Message/Text.vue index c9f969b835..4f2bb5554c 100644 --- a/src/views/chat/components/Message/Text.vue +++ b/src/views/chat/components/Message/Text.vue @@ -1,11 +1,12 @@