diff --git a/packages/review-editor/App.tsx b/packages/review-editor/App.tsx index 2e1faab..a9ae65b 100644 --- a/packages/review-editor/App.tsx +++ b/packages/review-editor/App.tsx @@ -893,6 +893,26 @@ const ReviewApp: React.FC = () => { setAnnotations(prev => [...prev, withPRContext(newAnnotation)]); }, [files, activeFileIndex, identity, withPRContext]); + const handleAddFileCommentForFile = useCallback((filePath: string, text: string) => { + const trimmed = text.trim(); + if (!trimmed) return; + + const newAnnotation: CodeAnnotation = { + id: generateId(), + type: 'comment', + scope: 'file', + filePath, + lineStart: 1, + lineEnd: 1, + side: 'new', + text: trimmed, + createdAt: Date.now(), + author: identity, + }; + + setAnnotations(prev => [...prev, withPRContext(newAnnotation)]); + }, [identity, withPRContext]); + // Edit annotation const handleEditAnnotation = useCallback(( id: string, @@ -1304,6 +1324,7 @@ const ReviewApp: React.FC = () => { onAddAnnotation: handleAddAnnotation, onAddAnnotationForFile: handleAddAnnotationForFile, onAddFileComment: handleAddFileComment, + onAddFileCommentForFile: handleAddFileCommentForFile, onEditAnnotation: handleEditAnnotation, onSelectAnnotation: handleSelectAnnotation, onDeleteAnnotation: handleDeleteAnnotation, @@ -1344,7 +1365,7 @@ const ReviewApp: React.FC = () => { diffFontFamily, diffFontSize, activeDiffBase, committedBase, feedbackDiffContext, prReviewScopeLabel, prDiffScope, allAnnotations, externalAnnotations, selectedAnnotationId, pendingSelection, handleLineSelection, - handleAddAnnotation, handleAddFileComment, handleEditAnnotation, + handleAddAnnotation, handleAddFileComment, handleAddFileCommentForFile, handleEditAnnotation, handleSelectAnnotation, handleDeleteAnnotation, viewedFiles, handleToggleViewed, stagedFiles, stagingFile, stageFile, canStageFiles, stageError, isSearchPending, debouncedSearchQuery, diff --git a/packages/review-editor/components/AllFilesDiffView.tsx b/packages/review-editor/components/AllFilesDiffView.tsx index 04d4223..c02525a 100644 --- a/packages/review-editor/components/AllFilesDiffView.tsx +++ b/packages/review-editor/components/AllFilesDiffView.tsx @@ -11,6 +11,7 @@ import { InlineAnnotation } from './InlineAnnotation'; import { AnnotationToolbar } from './AnnotationToolbar'; import { SuggestionModal } from './SuggestionModal'; import { FileHeader } from './FileHeader'; +import { CommentPopover } from '@plannotator/ui/components/CommentPopover'; import { detectLanguage } from '../utils/detectLanguage'; import type { DiffFile } from '../types'; import { buildFileTree, getVisualFileOrder } from '../utils/buildFileTree'; @@ -23,6 +24,7 @@ interface AllFilesDiffViewProps { pendingSelection: SelectedLineRange | null; onLineSelection: (range: SelectedLineRange | null) => void; onAddAnnotation: (filePath: string, type: CodeAnnotationType, text?: string, suggestedCode?: string, originalCode?: string, conventionalLabel?: ConventionalLabel, decorations?: ConventionalDecoration[], tokenMeta?: TokenAnnotationMeta) => void; + onAddFileComment?: (filePath: string, text: string) => void; onEditAnnotation: (id: string, text?: string, suggestedCode?: string, originalCode?: string, conventionalLabel?: ConventionalLabel | null, decorations?: ConventionalDecoration[]) => void; onSelectAnnotation: (id: string | null) => void; onDeleteAnnotation: (id: string) => void; @@ -55,6 +57,7 @@ export const AllFilesDiffView: React.FC = ({ pendingSelection, onLineSelection, onAddAnnotation, + onAddFileComment, onEditAnnotation, onSelectAnnotation, onDeleteAnnotation, @@ -84,6 +87,7 @@ export const AllFilesDiffView: React.FC = ({ const pendingToolbarRange = useRef(null); const [collapsedFiles, setCollapsedFiles] = useState>(new Set()); const collapseHistory = useRef([]); + const [fileCommentAnchor, setFileCommentAnchor] = useState<{ el: HTMLElement; filePath: string } | null>(null); useEffect(() => { setActiveFilePath(null); @@ -233,12 +237,24 @@ export const AllFilesDiffView: React.FC = ({ return; } - if (e.key === 'c' && currentPath) { + if (e.key === 'x' && currentPath) { e.preventDefault(); toggleCollapse(currentPath); return; } + if (e.key === 'c' && currentPath && onAddFileComment) { + e.preventDefault(); + const header = headerRefs.current.get(currentPath); + if (header) { + const btn = header.querySelector('[title="Add file-scoped comment"]'); + if (btn) { + setFileCommentAnchor({ el: btn, filePath: currentPath }); + } + } + return; + } + if (e.key === 'v' && currentPath) { e.preventDefault(); const isCurrentlyViewed = viewedFiles.has(currentPath); @@ -285,7 +301,7 @@ export const AllFilesDiffView: React.FC = ({ }; window.addEventListener('keydown', handler); return () => window.removeEventListener('keydown', handler); - }, [isActive, sortedFiles, collapsedFiles, activeFilePath, toggleCollapse, viewedFiles, onToggleViewed, canStageFiles, onStage]); + }, [isActive, sortedFiles, collapsedFiles, activeFilePath, toggleCollapse, viewedFiles, onToggleViewed, canStageFiles, onStage, onAddFileComment]); // Click-and-drag line selection in diff content useEffect(() => { @@ -412,6 +428,7 @@ export const AllFilesDiffView: React.FC = ({ } onCollapseToggle={() => toggleCollapse(file.path)} + onFileComment={onAddFileComment ? (anchorEl) => setFileCommentAnchor({ el: anchorEl, filePath: file.path }) : undefined} /> {!isCollapsed && ( @@ -522,6 +539,19 @@ export const AllFilesDiffView: React.FC = ({ onClose={() => toolbar.setShowCodeModal(false)} /> )} + + {fileCommentAnchor && onAddFileComment && ( + { + onAddFileComment(fileCommentAnchor.filePath, text); + setFileCommentAnchor(null); + }} + onClose={() => setFileCommentAnchor(null)} + /> + )} ); }; diff --git a/packages/review-editor/dock/ReviewStateContext.tsx b/packages/review-editor/dock/ReviewStateContext.tsx index d7b1558..24b47c2 100644 --- a/packages/review-editor/dock/ReviewStateContext.tsx +++ b/packages/review-editor/dock/ReviewStateContext.tsx @@ -50,6 +50,7 @@ export interface ReviewState { onAddAnnotation: (type: CodeAnnotationType, text?: string, suggestedCode?: string, originalCode?: string, conventionalLabel?: ConventionalLabel, decorations?: ConventionalDecoration[], tokenMeta?: TokenAnnotationMeta) => void; onAddAnnotationForFile: (filePath: string, type: CodeAnnotationType, text?: string, suggestedCode?: string, originalCode?: string, conventionalLabel?: ConventionalLabel, decorations?: ConventionalDecoration[], tokenMeta?: TokenAnnotationMeta) => void; onAddFileComment: (text: string) => void; + onAddFileCommentForFile: (filePath: string, text: string) => void; onEditAnnotation: (id: string, text?: string, suggestedCode?: string, originalCode?: string, conventionalLabel?: ConventionalLabel | null, decorations?: ConventionalDecoration[]) => void; onSelectAnnotation: (id: string | null) => void; onDeleteAnnotation: (id: string) => void; diff --git a/packages/review-editor/dock/panels/ReviewAllFilesDiffPanel.tsx b/packages/review-editor/dock/panels/ReviewAllFilesDiffPanel.tsx index b42f28e..2178709 100644 --- a/packages/review-editor/dock/panels/ReviewAllFilesDiffPanel.tsx +++ b/packages/review-editor/dock/panels/ReviewAllFilesDiffPanel.tsx @@ -14,6 +14,7 @@ export const ReviewAllFilesDiffPanel: React.FC = () => { pendingSelection={state.pendingSelection} onLineSelection={state.onLineSelection} onAddAnnotation={state.onAddAnnotationForFile} + onAddFileComment={state.onAddFileCommentForFile} onEditAnnotation={state.onEditAnnotation} onSelectAnnotation={state.onSelectAnnotation} onDeleteAnnotation={state.onDeleteAnnotation} diff --git a/packages/ui/components/KeyboardShortcuts.tsx b/packages/ui/components/KeyboardShortcuts.tsx index 9b4fd68..a8bc0c7 100644 --- a/packages/ui/components/KeyboardShortcuts.tsx +++ b/packages/ui/components/KeyboardShortcuts.tsx @@ -138,7 +138,8 @@ const reviewShortcuts: ShortcutSection[] = [ shortcuts: [ { keys: ['V'], desc: 'Toggle viewed', hint: 'In all-files view, also collapses the file' }, { keys: ['A'], desc: 'Toggle git add / stage' }, - { keys: ['C'], desc: 'Collapse / expand file', hint: 'In all-files view, toggles the focused file' }, + { keys: ['C'], desc: 'File comment', hint: 'In all-files view, opens the comment popover for the focused file' }, + { keys: ['X'], desc: 'Collapse / expand file', hint: 'In all-files view, toggles the focused file' }, { keys: ['Z'], desc: 'Undo collapse', hint: 'Reopens the last collapsed file and scrolls to it' }, ], },