feat(frontend): 長いテキストをペーストした際にテキストファイルとして添付するかどうかを選択できるように (#13862)

* feat(frontend): ask if attach as file if clipboard text is very long

* docs(changelog): 長いテキストをペーストした際にテキストファイルとして添付するかどうかを選択できるように
This commit is contained in:
anatawa12
2024-05-23 13:15:22 +09:00
committed by GitHub
parent ed432d06d7
commit aafa669cf5
4 changed files with 24 additions and 1 deletions

View File

@@ -612,6 +612,23 @@ async function onPaste(ev: ClipboardEvent) {
quoteId.value = paste.substring(url.length).match(/^\/notes\/(.+?)\/?$/)?.[1] ?? null;
});
}
if (paste.length > 1000) {
ev.preventDefault();
os.confirm({
type: 'info',
text: i18n.ts.attachAsFileQuestion,
}).then(({ canceled }) => {
if (canceled) {
insertTextAtCursor(textareaEl.value, paste);
return;
}
const fileName = formatTimeString(new Date(), defaultStore.state.pastedFileName).replace(/{{number}}/g, "0");
const file = new File([paste], `${fileName}.txt`, { type: "text/plain" });
upload(file, `${fileName}.txt`);
});
}
}
function onDragover(ev) {