fix: AI chat receives live editor content instead of stale disk content

handleContentChange now syncs content to tab state on every editor
change (not just on Cmd+S save). This ensures the AI panel's context
snapshot always contains the current editor body, fixing the bug where
the AI reported empty note bodies for unsaved edits.

Root cause: pendingContentRef buffered content for save but never
updated notes.tabs[].content, so activeTab?.content (used by the AI
context builder) always reflected the last-saved disk content.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
lucaronin
2026-03-08 15:05:01 +01:00
parent 5290e1847d
commit d41fe306fe
2 changed files with 22 additions and 2 deletions

View File

@@ -66,10 +66,14 @@ export function useEditorSave({ updateVaultContent, setTabs, setToastMessage, on
}
}, [flushPending, setToastMessage, onAfterSave, saveNote, onNotePersisted])
/** Called by Editor onChange — buffers the latest content without saving */
/** Called by Editor onChange — buffers the latest content and syncs tab state
* so consumers (e.g. AI panel) always see current editor content. */
const handleContentChange = useCallback((path: string, content: string) => {
pendingContentRef.current = { path, content }
}, [])
setTabs((prev: Tab[]) =>
prev.map((t) => t.entry.path === path ? { ...t, content } : t)
)
}, [setTabs])
/** Save pending content for a specific path (used before rename) */
const savePendingForPath = useCallback(