Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 50 additions & 2 deletions src/components/RightSidebar/CodeReview/ReviewPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export const ReviewPanel: React.FC<ReviewPanelProps> = ({
);

// Initialize review state hook
const { isRead, toggleRead } = useReviewState(workspaceId);
const { isRead, toggleRead, markAsRead, markAsUnread } = useReviewState(workspaceId);

const [filters, setFilters] = useState<ReviewFiltersType>({
showReadHunks: showReadHunks,
Expand Down Expand Up @@ -419,6 +419,39 @@ export const ReviewPanel: React.FC<ReviewPanelProps> = ({
[isRead, toggleRead, filters.showReadHunks, hunks, selectedHunkId]
);

// Handle marking hunk as read with auto-navigation
const handleMarkAsRead = useCallback(
(hunkId: string) => {
const wasRead = isRead(hunkId);
markAsRead(hunkId);

// If marking the selected hunk as read and it will be filtered out, navigate
if (hunkId === selectedHunkId && !wasRead && !filters.showReadHunks) {
// Hunk will be filtered out - move to next visible hunk
const currentFiltered = hunks.filter((h) => !isRead(h.id));
const currentIndex = currentFiltered.findIndex((h) => h.id === hunkId);
if (currentIndex !== -1) {
if (currentIndex < currentFiltered.length - 1) {
setSelectedHunkId(currentFiltered[currentIndex + 1].id);
} else if (currentIndex > 0) {
setSelectedHunkId(currentFiltered[currentIndex - 1].id);
} else {
setSelectedHunkId(null);
}
}
}
},
[isRead, markAsRead, filters.showReadHunks, hunks, selectedHunkId]
);

// Handle marking hunk as unread (no navigation needed - unread hunks are always visible)
const handleMarkAsUnread = useCallback(
(hunkId: string) => {
markAsUnread(hunkId);
},
[markAsUnread]
);

// Stable callbacks for HunkViewer (single callback shared across all hunks)
const handleHunkClick = useCallback((e: React.MouseEvent<HTMLElement>) => {
const hunkId = e.currentTarget.dataset.hunkId;
Expand Down Expand Up @@ -496,6 +529,14 @@ export const ReviewPanel: React.FC<ReviewPanelProps> = ({
// Toggle read state of selected hunk
e.preventDefault();
handleToggleRead(selectedHunkId);
} else if (matchesKeybind(e, KEYBINDS.MARK_HUNK_READ)) {
// Mark selected hunk as read
e.preventDefault();
handleMarkAsRead(selectedHunkId);
} else if (matchesKeybind(e, KEYBINDS.MARK_HUNK_UNREAD)) {
// Mark selected hunk as unread
e.preventDefault();
handleMarkAsUnread(selectedHunkId);
} else if (matchesKeybind(e, KEYBINDS.TOGGLE_HUNK_COLLAPSE)) {
// Toggle expand/collapse state of selected hunk
e.preventDefault();
Expand All @@ -508,7 +549,14 @@ export const ReviewPanel: React.FC<ReviewPanelProps> = ({

window.addEventListener("keydown", handleKeyDown);
return () => window.removeEventListener("keydown", handleKeyDown);
}, [isPanelFocused, selectedHunkId, filteredHunks, handleToggleRead]);
}, [
isPanelFocused,
selectedHunkId,
filteredHunks,
handleToggleRead,
handleMarkAsRead,
handleMarkAsUnread,
]);

// Global keyboard shortcuts (Ctrl+R / Cmd+R for refresh, Ctrl+F / Cmd+F for search)
useEffect(() => {
Expand Down
6 changes: 6 additions & 0 deletions src/utils/ui/keybinds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,12 @@ export const KEYBINDS = {
/** Mark selected hunk as read/unread in Code Review panel */
TOGGLE_HUNK_READ: { key: "m" },

/** Mark selected hunk as read in Code Review panel */
MARK_HUNK_READ: { key: "l" },

/** Mark selected hunk as unread in Code Review panel */
MARK_HUNK_UNREAD: { key: "h" },

/** Toggle hunk expand/collapse in Code Review panel */
TOGGLE_HUNK_COLLAPSE: { key: " " },
} as const;