From 27e1d7148809df2cbfce89c4846d72800f294736 Mon Sep 17 00:00:00 2001 From: lucaronin Date: Tue, 17 Feb 2026 12:07:23 +0100 Subject: [PATCH] refactor: extract DiffView into its own file from Editor.tsx --- src/components/DiffView.tsx | 45 +++++++++++++++++++++++++++++++++++++ src/components/Editor.tsx | 41 ++------------------------------- 2 files changed, 47 insertions(+), 39 deletions(-) create mode 100644 src/components/DiffView.tsx diff --git a/src/components/DiffView.tsx b/src/components/DiffView.tsx new file mode 100644 index 00000000..e8aff793 --- /dev/null +++ b/src/components/DiffView.tsx @@ -0,0 +1,45 @@ +import { cn } from '@/lib/utils' + +interface DiffViewProps { + diff: string +} + +export function DiffView({ diff }: DiffViewProps) { + if (!diff) { + return ( +
+ No changes to display +
+ ) + } + + const lines = diff.split('\n') + + return ( +
+ {lines.map((line, i) => { + let lineClass = 'text-secondary-foreground' + if (line.startsWith('+') && !line.startsWith('+++')) { + lineClass = 'bg-[rgba(76,175,80,0.12)] text-[#4caf50]' + } else if (line.startsWith('-') && !line.startsWith('---')) { + lineClass = 'bg-[rgba(244,67,54,0.12)] text-[#f44336]' + } else if (line.startsWith('@@')) { + lineClass = 'bg-[rgba(33,150,243,0.08)] text-primary italic' + } else if (line.startsWith('diff') || line.startsWith('index') || line.startsWith('---') || line.startsWith('+++') || line.startsWith('new file')) { + lineClass = 'bg-muted text-muted-foreground font-semibold' + } + + return ( +
+ + {i + 1} + + + {line || '\u00A0'} + +
+ ) + })} +
+ ) +} diff --git a/src/components/Editor.tsx b/src/components/Editor.tsx index f08cbe91..f2e83fe0 100644 --- a/src/components/Editor.tsx +++ b/src/components/Editor.tsx @@ -6,6 +6,7 @@ import { BlockNoteView } from '@blocknote/mantine' import '@blocknote/mantine/style.css' import type { VaultEntry, GitCommit } from '../types' import { Inspector, type FrontmatterValue } from './Inspector' +import { DiffView } from './DiffView' import { ResizeHandle } from './ResizeHandle' import { useEditorTheme } from '../hooks/useTheme' import { cn } from '@/lib/utils' @@ -145,45 +146,7 @@ function expandWikilinksInContent(content: any[]): any[] { return result } -function DiffView({ diff }: { diff: string }) { - if (!diff) { - return ( -
- No changes to display -
- ) - } - - const lines = diff.split('\n') - - return ( -
- {lines.map((line, i) => { - let lineClass = 'text-secondary-foreground' - if (line.startsWith('+') && !line.startsWith('+++')) { - lineClass = 'bg-[rgba(76,175,80,0.12)] text-[#4caf50]' - } else if (line.startsWith('-') && !line.startsWith('---')) { - lineClass = 'bg-[rgba(244,67,54,0.12)] text-[#f44336]' - } else if (line.startsWith('@@')) { - lineClass = 'bg-[rgba(33,150,243,0.08)] text-primary italic' - } else if (line.startsWith('diff') || line.startsWith('index') || line.startsWith('---') || line.startsWith('+++') || line.startsWith('new file')) { - lineClass = 'bg-muted text-muted-foreground font-semibold' - } - - return ( -
- - {i + 1} - - - {line || '\u00A0'} - -
- ) - })} -
- ) -} +// DiffView extracted to ./DiffView.tsx /** Inner component that creates/manages BlockNote for a single tab */ function BlockNoteTab({ content, entries, onNavigateWikilink }: { content: string; entries: VaultEntry[]; onNavigateWikilink: (target: string) => void }) {