Skip to content

Commit 2c5a41f

Browse files
authored
🤖 feat: add Shift+M shortcut to mark entire file as read in code review (#560)
When reviewing code with many hunks per file, marking each hunk individually is tedious. **Shift+M** now marks all hunks in the current file as read at once. **Implementation:** - New `MARK_FILE_READ` keybind triggers `handleMarkFileAsRead` - Finds all hunks with matching `filePath` and calls existing `markAsRead(array)` - Smart navigation: when hiding read hunks, jumps to next unread file automatically - Tooltip updated to show both shortcuts: **M** (single hunk) and **Shift+M** (whole file) **Verify:** Open review tab, select a hunk, press Shift+M. All hunks in that file should be marked read. _Generated with `cmux`_
1 parent 83a5273 commit 2c5a41f

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

‎src/components/RightSidebar/CodeReview/HunkViewer.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ export const HunkViewer = React.memo<HunkViewerProps>(
230230
{isRead ? "â—‹" : "â—‰"}
231231
</button>
232232
<Tooltip align="right" position="top">
233-
Mark as read ({formatKeybind(KEYBINDS.TOGGLE_HUNK_READ)})
233+
Mark as read ({formatKeybind(KEYBINDS.TOGGLE_HUNK_READ)}) · Mark file (
234+
{formatKeybind(KEYBINDS.MARK_FILE_READ)})
234235
</Tooltip>
235236
</TooltipWrapper>
236237
)}

‎src/components/RightSidebar/CodeReview/ReviewPanel.tsx‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,33 @@ export const ReviewPanel: React.FC<ReviewPanelProps> = ({
467467
toggleExpandFnsRef.current.set(hunkId, toggleFn);
468468
}, []);
469469

470+
// Handle marking all hunks in a file as read
471+
const handleMarkFileAsRead = useCallback(
472+
(hunkId: string) => {
473+
// Find the hunk to determine its file path
474+
const hunk = hunks.find((h) => h.id === hunkId);
475+
if (!hunk) return;
476+
477+
// Find all hunks in the same file
478+
const fileHunkIds = hunks.filter((h) => h.filePath === hunk.filePath).map((h) => h.id);
479+
480+
// Mark all hunks in the file as read
481+
markAsRead(fileHunkIds);
482+
483+
// If marking the selected hunk's file as read and hunks will be filtered out, navigate
484+
if (hunkId === selectedHunkId && !filters.showReadHunks) {
485+
// Find the next visible hunk that's not in the same file
486+
const currentFiltered = hunks.filter((h) => !isRead(h.id) && h.filePath !== hunk.filePath);
487+
if (currentFiltered.length > 0) {
488+
setSelectedHunkId(currentFiltered[0].id);
489+
} else {
490+
setSelectedHunkId(null);
491+
}
492+
}
493+
},
494+
[hunks, markAsRead, isRead, filters.showReadHunks, selectedHunkId]
495+
);
496+
470497
// Calculate stats
471498
const stats = useMemo(() => {
472499
const total = hunks.length;
@@ -534,6 +561,10 @@ export const ReviewPanel: React.FC<ReviewPanelProps> = ({
534561
// Mark selected hunk as unread
535562
e.preventDefault();
536563
handleMarkAsUnread(selectedHunkId);
564+
} else if (matchesKeybind(e, KEYBINDS.MARK_FILE_READ)) {
565+
// Mark entire file (all hunks) as read
566+
e.preventDefault();
567+
handleMarkFileAsRead(selectedHunkId);
537568
} else if (matchesKeybind(e, KEYBINDS.TOGGLE_HUNK_COLLAPSE)) {
538569
// Toggle expand/collapse state of selected hunk
539570
e.preventDefault();
@@ -553,6 +584,7 @@ export const ReviewPanel: React.FC<ReviewPanelProps> = ({
553584
handleToggleRead,
554585
handleMarkAsRead,
555586
handleMarkAsUnread,
587+
handleMarkFileAsRead,
556588
]);
557589

558590
// Global keyboard shortcuts (Ctrl+R / Cmd+R for refresh, Ctrl+F / Cmd+F for search)

‎src/utils/ui/keybinds.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ export const KEYBINDS = {
276276
/** Mark selected hunk as unread in Code Review panel */
277277
MARK_HUNK_UNREAD: { key: "h" },
278278

279+
/** Mark entire file (all hunks) as read in Code Review panel */
280+
MARK_FILE_READ: { key: "M", shift: true },
281+
279282
/** Toggle hunk expand/collapse in Code Review panel */
280283
TOGGLE_HUNK_COLLAPSE: { key: " " },
281284
} as const;

0 commit comments

Comments
 (0)