()
| 186 | } |
| 187 | |
| 188 | private async createNewFile(): Promise<void> { |
| 189 | if (!this.currentQuery) { |
| 190 | new Notice("Please enter a file name"); |
| 191 | return; |
| 192 | } |
| 193 | |
| 194 | try { |
| 195 | let fileName = this.currentQuery; |
| 196 | // Remove .md extension if user typed it (we'll add it back) |
| 197 | if (fileName.toLowerCase().endsWith(".md")) { |
| 198 | fileName = fileName.slice(0, -3); |
| 199 | } |
| 200 | |
| 201 | // Determine the folder |
| 202 | const folderPath = this.options.newFileFolder || ""; |
| 203 | const filePath = folderPath ? `${folderPath}/${fileName}.md` : `${fileName}.md`; |
| 204 | |
| 205 | // Check if file already exists |
| 206 | const existingFile = this.app.vault.getAbstractFileByPath(filePath); |
| 207 | if (existingFile) { |
| 208 | new Notice(`File "${filePath}" already exists`); |
| 209 | return; |
| 210 | } |
| 211 | |
| 212 | // Ensure folder exists (check on-disk via adapter, not in-memory cache) |
| 213 | if (folderPath && !(await this.app.vault.adapter.exists(folderPath))) { |
| 214 | await createVaultFolder(this.app, folderPath); |
| 215 | } |
| 216 | |
| 217 | // Create the file |
| 218 | const newFile = await createVaultFile(this.app, filePath, ""); |
| 219 | |
| 220 | this.resultHandled = true; |
| 221 | this.close(); |
| 222 | this.options.onResult({ type: "created", file: newFile }); |
| 223 | } catch (error) { |
| 224 | tasknotesLogger.error("Error creating file:", { |
| 225 | category: "persistence", |
| 226 | operation: "creating-file", |
| 227 | error: error, |
| 228 | }); |
| 229 | new Notice("Failed to create file"); |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | getSuggestions(query: string): TAbstractFile[] { |
| 234 | this.currentQuery = query.trim(); |
no test coverage detected