Create downloadText wrapper for downloadUri and use it, use string interpolation for filename
This commit is contained in:
parent
aefb7d56db
commit
d7c14f1c60
1 changed files with 11 additions and 7 deletions
18
src/App.tsx
18
src/App.tsx
|
@ -90,6 +90,13 @@ function downloadUri(uri: string, filename: string) {
|
|||
downloadAnchor.click();
|
||||
}
|
||||
|
||||
function downloadText(text: string, fileName: string) {
|
||||
const file = new File([text], fileName);
|
||||
const url = URL.createObjectURL(file);
|
||||
downloadUri(url, fileName);
|
||||
URL.revokeObjectURL(url)
|
||||
}
|
||||
|
||||
async function getFileUploadWithDialog() {
|
||||
const uploadInput = document.createElement("input");
|
||||
uploadInput.type = "file";
|
||||
|
@ -222,13 +229,10 @@ function App() {
|
|||
function handleDownloadFile() {
|
||||
const model = editor?.getModel();
|
||||
if (!model || !editor) return;
|
||||
const text = model.getValue();
|
||||
const languageExtension = getFileExtension(language);
|
||||
const fileName = "unknown." + languageExtension;
|
||||
const file = new File([text], fileName);
|
||||
const url = URL.createObjectURL(file);
|
||||
downloadUri(url, fileName);
|
||||
URL.revokeObjectURL(url);
|
||||
downloadText(
|
||||
model.getValue(),
|
||||
`rustpad.${getFileExtension(language)}`,
|
||||
)
|
||||
}
|
||||
|
||||
useKeyboardCtrlIntercept("s", handleDownloadFile);
|
||||
|
|
Loading…
Add table
Reference in a new issue