Skip to content

Commit ec43387

Browse files
committed
update
1 parent b4d3bc1 commit ec43387

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

frontend/src/hooks/useEditor.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,35 @@ export function useEditor() {
154154
return;
155155
}
156156

157-
// No explicit path available: do nothing silently.
157+
const rawLabel = activeTab.label.trim() || "Untitled";
158+
const suggestedName = /\.[A-Za-z0-9]+$/.test(rawLabel) ? rawLabel : `${rawLabel}.md`;
159+
160+
try {
161+
const { save } = await import("@tauri-apps/plugin-dialog");
162+
const selected = await save({
163+
defaultPath: suggestedName,
164+
filters: [{ name: "Markdown", extensions: ["md", "markdown", "txt"] }],
165+
});
166+
167+
if (!selected) return;
168+
169+
const resolvedPath = Array.isArray(selected) ? selected[0] : selected;
170+
await Files.write(resolvedPath, activeTab.content);
171+
updateTab(activeTabId, {
172+
dirty: false,
173+
filePath: resolvedPath,
174+
browserHandle: null,
175+
label: resolvedPath.split(/[/\\]/).pop() ?? resolvedPath,
176+
});
177+
Files.addRecent(resolvedPath)
178+
.then(({ entries }) => setRecentFiles(entries))
179+
.catch(console.error);
180+
return;
181+
} catch {
182+
// Outside Tauri native runtime, keep silent.
183+
}
184+
185+
// No explicit path available and no native save dialog capability.
158186
return;
159187
},
160188
[activeTab, activeTabId, updateTab]

0 commit comments

Comments
 (0)