* Saves a file to it's location, if file is new, it will ask for location * @param {EditorFile} file * @param {boolean} [isSaveAs]
(file, isSaveAs = false)
| 20 | * @param {boolean} [isSaveAs] |
| 21 | */ |
| 22 | async function saveFile(file, isSaveAs = false) { |
| 23 | // If file is loading, return |
| 24 | if (file.loading) return; |
| 25 | |
| 26 | /** |
| 27 | * If set, new file needs to be created |
| 28 | * @type {string} |
| 29 | */ |
| 30 | let newUrl; |
| 31 | /** |
| 32 | * File operation object |
| 33 | * @type {fsOperation} |
| 34 | */ |
| 35 | let fileOnDevice; |
| 36 | /** |
| 37 | * File name, can be changed by user |
| 38 | * @type {string} |
| 39 | */ |
| 40 | let { filename } = file; |
| 41 | /** |
| 42 | * If file is new |
| 43 | * @type {boolean} |
| 44 | */ |
| 45 | let isNewFile = false; |
| 46 | |
| 47 | /** |
| 48 | * Encoding of file |
| 49 | * @type {string} |
| 50 | */ |
| 51 | const { encoding } = file; |
| 52 | /** |
| 53 | * File tab bar text element, used to show saving status |
| 54 | * @type {HTMLElement} |
| 55 | */ |
| 56 | const $text = file.tab.querySelector("span.text"); |
| 57 | |
| 58 | if (!file.uri) { |
| 59 | isNewFile = true; |
| 60 | } else { |
| 61 | isSaveAs = isSaveAs ?? file.readOnly; |
| 62 | } |
| 63 | |
| 64 | if (isSaveAs || isNewFile) { |
| 65 | const option = await recents.select( |
| 66 | [[SELECT_FOLDER, strings["select folder"], "folder"]], // options |
| 67 | "dir", // type |
| 68 | strings["select folder"], // title |
| 69 | ); |
| 70 | |
| 71 | if (option === SELECT_FOLDER) { |
| 72 | newUrl = await selectFolder(); |
| 73 | } else { |
| 74 | newUrl = option.val.url; |
| 75 | } |
| 76 | |
| 77 | if (isSaveAs) { |
| 78 | filename = await getfilename(newUrl, file.filename); |
| 79 | } else { |
no test coverage detected