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.outline = "none";
|
||||||
textarea.style.boxShadow = "none";
|
textarea.style.boxShadow = "none";
|
||||||
textarea.style.background = "transparent";
|
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.focus();
|
||||||
textarea.select();
|
textarea.select();
|
||||||
try {
|
try {
|
||||||
document.execCommand("copy");
|
document.execCommand("copy");
|
||||||
document.body.removeChild(textarea);
|
|
||||||
resolve();
|
resolve();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
document.body.removeChild(textarea);
|
|
||||||
reject(e);
|
reject(e);
|
||||||
|
}finally{
|
||||||
|
body.removeChild(textarea)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
reject(
|
reject(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user