v1.1.8 - Fix unsaved content lost when switching notes

This commit is contained in:
Yuri Karamian committed 2026-02-24 23:32:14 +01:00
1 parent d098066899
commit 0b5db1340c
6 files changed
+35 -4

No files matched your search

+30
View File
@@ -1200,6 +1200,21 @@
}
export function loadNote(path: string, content: string) {
// Flush any unsaved changes for the CURRENT note before loading the new one
if ($editorDirty && $activeNote && $activeNotePath && $activeNotePath !== path) {
try {
const body = $sourceMode
? restoreTitleH1(sourceContent)
: editorToMarkdown();
const trimmed = body.replace(/^#.*\n?/, '').trim();
if (trimmed || !$activeNote.content || $activeNote.content.trim().length <= 10) {
saveNote($activeNotePath, $activeNote.meta, body);
}
} catch (e) {
console.error('Pre-switch save failed:', e);
}
$editorDirty = false;
}
loadedPath = path;
lastSourceMode = $sourceMode;
isLoadingNote = true;
@@ -1997,6 +2012,21 @@
});
function destroyEditor() {
// Flush unsaved changes before destroying
if ($editorDirty && $activeNote && $activeNotePath && editor) {
try {
const body = $sourceMode
? restoreTitleH1(sourceContent)
: editorToMarkdown();
const trimmed = body.replace(/^#.*\n?/, '').trim();
if (trimmed || !$activeNote.content || $activeNote.content.trim().length <= 10) {
saveNote($activeNotePath, $activeNote.meta, body);
}
} catch (e) {
console.error('Destroy-save failed:', e);
}
$editorDirty = false;
}
if (editor) {
editor.destroy();
editor = null;
+1
View File
@@ -127,6 +127,7 @@
<div class="shortcut-row"><span class="shortcut-desc">Go back</span><span class="shortcut-keys"><kbd>Alt</kbd>+<kbd>←</kbd></span></div>
<div class="shortcut-row"><span class="shortcut-desc">Go forward</span><span class="shortcut-keys"><kbd>Alt</kbd>+<kbd>→</kbd></span></div>
<div class="shortcut-row"><span class="shortcut-desc">Toggle source mode</span><span class="shortcut-keys"><kbd>{modKey}</kbd>+<kbd>Shift</kbd>+<kbd>M</kbd></span></div>
<div class="shortcut-row"><span class="shortcut-desc">Open note in new window</span><span class="shortcut-keys"><kbd>{modKey}</kbd>+<kbd>Shift</kbd>+<kbd>W</kbd></span></div>
<div class="shortcut-row"><span class="shortcut-desc">Exit focus mode</span><span class="shortcut-keys"><kbd>Esc</kbd></span></div>
<h4 class="shortcuts-group-title">Editor Commands</h4>