diff --git a/src/renderer/hooks/use-export-source.ts b/src/renderer/hooks/use-export-source.ts new file mode 100644 index 0000000..d79add2 --- /dev/null +++ b/src/renderer/hooks/use-export-source.ts @@ -0,0 +1,26 @@ +import { useFileStore } from '@/stores/file-store'; +import { useEditorStore } from '@/stores/editor-store'; + +export interface ExportSource { + source: string; + path: string; + title: string; +} + +/** + * Read the active buffer's content from the editor store. Returns null if + * no buffer is open. Components handle the null case (prompt to open a file). + */ +export function useExportSource(): ExportSource | null { + const activeTabId = useFileStore((s) => s.activeTabId); + const openTabs = useFileStore((s) => s.openTabs); + const buffer = useEditorStore((s) => (activeTabId ? s.buffers.get(activeTabId) : undefined)); + + if (!activeTabId || !buffer) return null; + const tab = openTabs.find((t) => t.id === activeTabId); + return { + source: buffer.content, + path: activeTabId, + title: tab?.title ?? activeTabId, + }; +} \ No newline at end of file