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:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user