Allow saving without file open (Save as... prompt)
This commit is contained in:
+17
-3
@@ -58,8 +58,8 @@
|
|||||||
<button @click="exportHTML" title="Export HTML">HTML</button>
|
<button @click="exportHTML" title="Export HTML">HTML</button>
|
||||||
<button @click="exportMD" title="Download .md">MD</button>
|
<button @click="exportMD" title="Download .md">MD</button>
|
||||||
</div>
|
</div>
|
||||||
<button class="save-btn" :class="{dirty: isDirty}" @click="saveFile">
|
<button class="save-btn" :class="{dirty: isDirty || (!currentFile && content)}" @click="saveFile">
|
||||||
{{ isDirty ? 'Save*' : 'Saved' }}
|
{{ !currentFile && content ? 'Save as...' : isDirty ? 'Save*' : 'Saved' }}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -308,7 +308,21 @@ async function openFile(path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function saveFile() {
|
async function saveFile() {
|
||||||
if (!currentFile.value) return
|
if (!currentFile.value) {
|
||||||
|
// No file open — prompt to create one
|
||||||
|
const name = prompt('Save as (e.g. notes.md):')
|
||||||
|
if (!name) return
|
||||||
|
let path = name
|
||||||
|
if (!path.endsWith('.md') && !path.endsWith('.txt')) {
|
||||||
|
path += '.md'
|
||||||
|
}
|
||||||
|
await api('/api/files/create', { path, content: content.value })
|
||||||
|
currentFile.value = path
|
||||||
|
isDirty.value = false
|
||||||
|
await loadFiles()
|
||||||
|
setTimeout(checkGitStatus, 1000)
|
||||||
|
return
|
||||||
|
}
|
||||||
await api('/api/files/write', { path: currentFile.value, content: content.value })
|
await api('/api/files/write', { path: currentFile.value, content: content.value })
|
||||||
isDirty.value = false
|
isDirty.value = false
|
||||||
setTimeout(checkGitStatus, 1000)
|
setTimeout(checkGitStatus, 1000)
|
||||||
|
|||||||
Reference in New Issue
Block a user