import { useEditorStore } from '@/stores/editor-store'; const HEADING_RE = /^(#{1,6})\s+(.+)$/gm; interface HeadingItem { level: number; text: string; line: number; } function extractHeadings(content: string): HeadingItem[] { const headings: HeadingItem[] = []; let match: RegExpExecArray | null; const re = new RegExp(HEADING_RE.source, 'gm'); let lineNum = 1; for (const line of content.split('\n')) { re.lastIndex = 0; match = re.exec(line); if (match) { headings.push({ level: match[1].length, text: match[2].trim(), line: lineNum, }); } lineNum++; } return headings; } export function Outline() { const activeId = useEditorStore((s) => s.activeId); const buffers = useEditorStore((s) => s.buffers); if (!activeId) { return (
No file open
); } const buffer = buffers.get(activeId); if (!buffer) { return (
No file open
); } const headings = extractHeadings(buffer.content); if (headings.length === 0) { return (
No headings
); } return (
{headings.map((h, i) => ( ))}
); }