Widen settings forms and fix Token clipboard copy fallback.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -150,6 +150,39 @@ export default function SettingsPage() {
|
||||
}
|
||||
}
|
||||
|
||||
async function copyToken(text: string) {
|
||||
setErr("");
|
||||
setOk("");
|
||||
try {
|
||||
if (navigator.clipboard?.writeText) {
|
||||
await navigator.clipboard.writeText(text);
|
||||
setOk("已复制到剪贴板");
|
||||
return;
|
||||
}
|
||||
} catch {
|
||||
/* fall through to legacy copy */
|
||||
}
|
||||
try {
|
||||
const ta = document.createElement("textarea");
|
||||
ta.value = text;
|
||||
ta.setAttribute("readonly", "");
|
||||
ta.style.position = "fixed";
|
||||
ta.style.left = "-9999px";
|
||||
document.body.appendChild(ta);
|
||||
ta.select();
|
||||
ta.setSelectionRange(0, text.length);
|
||||
const okCopy = document.execCommand("copy");
|
||||
document.body.removeChild(ta);
|
||||
if (okCopy) {
|
||||
setOk("已复制到剪贴板");
|
||||
return;
|
||||
}
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
setErr("复制失败,请手动选中 Token 复制");
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h2>系统设置</h2>
|
||||
@@ -297,10 +330,7 @@ export default function SettingsPage() {
|
||||
<button
|
||||
type="button"
|
||||
className="btn ghost"
|
||||
onClick={() => {
|
||||
void navigator.clipboard.writeText(lastToken.token);
|
||||
setOk("已复制到剪贴板");
|
||||
}}
|
||||
onClick={() => void copyToken(lastToken.token)}
|
||||
>
|
||||
复制
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user