Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: the copy method in clipboard.ts #3177

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 30 additions & 18 deletions frontend/src/utils/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,18 @@
document.queryCommandSupported &&
document.queryCommandSupported("copy")
) {
const textarea = document.createElement("textarea");
textarea.textContent = text;
textarea.setAttribute("readonly", "");
textarea.style.fontSize = "12pt";
textarea.style.position = "fixed";
textarea.style.width = "2em";
textarea.style.height = "2em";
textarea.style.padding = "0";
textarea.style.margin = "0";
textarea.style.border = "none";
textarea.style.outline = "none";
textarea.style.boxShadow = "none";
textarea.style.background = "transparent";
document.body.appendChild(textarea);
textarea.focus();
textarea.select();
const textarea = createTemporaryTextarea(text);
const body = document.activeElement || document.body;
try {
body.appendChild(textarea);
textarea.focus();
textarea.select();
document.execCommand("copy");
document.body.removeChild(textarea);
resolve();
} catch (e) {
document.body.removeChild(textarea);
reject(e);
} finally {
body.removeChild(textarea);
}
} else {
reject(
Expand All @@ -64,3 +53,26 @@
}
});
}

const styles = {
fontSize: "12pt",
position: "fixed",
top: 0,
left: 0,
width: "2em",
height: "2em",
padding: 0,
margin: 0,
border: "none",
outline: "none",
boxShadow: "none",
background: "transparent"

Check warning on line 69 in frontend/src/utils/clipboard.ts

View workflow job for this annotation

GitHub Actions / lint-frontend

Insert `,`
};

const createTemporaryTextarea = (text:string) => {

Check warning on line 72 in frontend/src/utils/clipboard.ts

View workflow job for this annotation

GitHub Actions / lint-frontend

Insert `·`
const textarea = document.createElement("textarea");
textarea.value = text;
textarea.setAttribute("readonly", "");
Object.assign(textarea.style, styles);
return textarea;
};

Check warning on line 78 in frontend/src/utils/clipboard.ts

View workflow job for this annotation

GitHub Actions / lint-frontend

Insert `⏎`
Loading