fix: the clipboard.ts to address the issue of text copying failure when accessing it from the internet and when a modal dialog is open.
This commit is contained in:
parent
236ca637f9
commit
6027da4206
@ -46,16 +46,25 @@ export function copy(text: string) {
|
||||
textarea.style.outline = "none";
|
||||
textarea.style.boxShadow = "none";
|
||||
textarea.style.background = "transparent";
|
||||
document.body.appendChild(textarea);
|
||||
|
||||
let body: Element | null = null;
|
||||
const focusedElement = document.activeElement;
|
||||
if (focusedElement){
|
||||
body = focusedElement
|
||||
}else{
|
||||
body = document.body
|
||||
}
|
||||
body.appendChild(textarea)
|
||||
|
||||
textarea.focus();
|
||||
textarea.select();
|
||||
try {
|
||||
document.execCommand("copy");
|
||||
document.body.removeChild(textarea);
|
||||
resolve();
|
||||
} catch (e) {
|
||||
document.body.removeChild(textarea);
|
||||
reject(e);
|
||||
}finally{
|
||||
body.removeChild(textarea)
|
||||
}
|
||||
} else {
|
||||
reject(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user