Skip to content

Commit

Permalink
Add save dialog for saving documents written without opening a file
Browse files Browse the repository at this point in the history
Set file data after saving such files
  • Loading branch information
ttytm committed Sep 23, 2023
1 parent e270c7e commit 202bb16
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions examples/C/text-editor/ui/js/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,18 @@ async function openFile() {

async function saveFile() {
const content = codeMirrorInstance.getValue();
if (supportsFilePicker && fileHandle) {
// Create a FileSystemWritableFileStream to write to
const writableStream = await fileHandle.createWritable();
await writableStream.write(content);
// Write to disk
await writableStream.close();
if (supportsFilePicker) {
if (fileHandle) {
// Create a FileSystemWritableFileStream to write to
const writableStream = await fileHandle.createWritable();
await writableStream.write(content);
// Write to disk
await writableStream.close();
} else {
fileHandle = await showSaveFilePicker();
saveFile();
setFile(await fileHandle.getFile());
}
} else {
// Download the file if using filePicker with a fileHandle for saving
// is not supported by the browser. E.g., in Firefox.
Expand Down

0 comments on commit 202bb16

Please sign in to comment.