Skip to content
Closed
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ is running so changes apply to open windows.
Set `settings.showWhitespace` to `true` to show whitespace-only changes in diffs and file line
counts; when it is `false`, Codiff hides those changes from the working-tree review state.

Set `settings.commentOnLineClick` to `false` to stop clicks and drags on diff lines from opening a
review comment draft. The comment button in the gutter still opens one.

```jsonc
{
"$schema": "https://raw.githubusercontent.com/nkzw-tech/codiff/main/core/config/codiff-config.schema.json",
Expand All @@ -141,6 +144,7 @@ counts; when it is `false`, Codiff hides those changes from the working-tree rev
"claudeModel": "claude-sonnet-4-6",
"codeFontFamily": "",
"codeFontSize": 13,
"commentOnLineClick": true,
"copyCommentsOnClose": false,
"diffStyle": "split",
"editorCommand": "",
Expand Down
1 change: 1 addition & 0 deletions config/defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"claudeModel": "claude-sonnet-4-6",
"codeFontFamily": "",
"codeFontSize": 13,
"commentOnLineClick": true,
"copyCommentsOnClose": false,
"diffStyle": "split",
"editorCommand": "",
Expand Down
1 change: 1 addition & 0 deletions core/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1714,6 +1714,7 @@ export default function App() {
agentLabel,
codeQualityFindings: state.codeQualityFindings,
collapsed,
commentOnLineClick: preferences.commentOnLineClick,
comments: visibleReviewComments,
commitMetadata,
diffLineHeight,
Expand Down
1 change: 1 addition & 0 deletions core/__tests__/App-render.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ const createCodiffMock = (overrides: Partial<Window['codiff']> = {}): Window['co
claudeModel: defaultSettings.claudeModel,
codeFontFamily: defaultSettings.codeFontFamily,
codeFontSize: defaultSettings.codeFontSize,
commentOnLineClick: true,
copyCommentsOnClose: true,
diffStyle: 'split' as const,
editorCommand: '',
Expand Down
43 changes: 43 additions & 0 deletions core/__tests__/ReviewCodeView-scroll.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2510,3 +2510,46 @@ test('line content clicks create review comments unless text is selected', async
});
expect(onCreateComment).toHaveBeenCalledTimes(3);
});

test('commentOnLineClick=false leaves comment creation to the gutter button', async () => {
const onCreateComment = vi.fn();
const file = createChangedFileWithPatch(
'src/click.ts',
'diff --git a/src/click.ts b/src/click.ts\n@@ -1 +1 @@\n-old\n+new\n',
);
await using _view = await renderReact(
<ReviewCodeViewHarness
commentOnLineClick={false}
files={[file]}
onCreateComment={onCreateComment}
/>,
);
const { item, onGutterUtilityClick, onLineClick, onLineSelectionEnd } =
getReviewCodeViewHandlers();
const range = { end: 1, side: 'additions' as const, start: 1 };
await act(async () => {
onLineClick(
{
annotationSide: 'additions',
event: nonInteractivePointerEvent,
lineNumber: 1,
},
{ item },
);
onLineSelectionEnd(range, { item });
await new Promise((resolve) => setTimeout(resolve, 0));
});
expect(onCreateComment).not.toHaveBeenCalled();
expect(codeViewMock.lastOptions?.enableLineSelection).toBe(false);
await act(async () => {
onGutterUtilityClick(range, { item });
await new Promise((resolve) => setTimeout(resolve, 0));
});
expect(onCreateComment).toHaveBeenCalledTimes(1);
expect(onCreateComment).toHaveBeenLastCalledWith({
filePath: 'src/click.ts',
lineNumber: 1,
sectionId: 'src/click.ts:unstaged',
side: 'additions',
});
});
10 changes: 10 additions & 0 deletions core/__tests__/config-defaults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ test('electron config normalizes sidebar position', () => {
).toBe('left');
});

test('electron config keeps commentOnLineClick only when it is a boolean', () => {
expect(readElectronConfig({}).settings.commentOnLineClick).toBe(true);
expect(
readElectronConfig({ settings: { commentOnLineClick: false } }).settings.commentOnLineClick,
).toBe(false);
expect(
readElectronConfig({ settings: { commentOnLineClick: 'no' } }).settings.commentOnLineClick,
).toBe(true);
});

test('electron config keeps custom walkthrough prompt text only when it is a string', () => {
expect(
readElectronConfig({
Expand Down
9 changes: 6 additions & 3 deletions core/app/components/ReviewCodeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2499,6 +2499,7 @@ export function ReviewCodeView({
bottomInset = codeViewLayout.paddingBottom,
codeQualityFindings = [],
collapsed,
commentOnLineClick = true,
comments,
commitMetadata,
diffLineHeight = DIFF_LINE_HEIGHT,
Expand Down Expand Up @@ -2561,6 +2562,7 @@ export function ReviewCodeView({
bottomInset?: number;
codeQualityFindings?: ReadonlyArray<PullRequestCodeQualityFinding>;
collapsed: ReadonlySet<string>;
commentOnLineClick?: boolean;
comments: ReadonlyArray<ReviewComment>;
commitMetadata: CommitMetadata | null;
diffLineHeight?: number;
Expand Down Expand Up @@ -3286,7 +3288,7 @@ export function ReviewCodeView({
diffIndicators: 'bars',
diffStyle,
enableGutterUtility: !isReadOnly,
enableLineSelection: !isReadOnly,
enableLineSelection: !isReadOnly && commentOnLineClick,
expandUnchanged: false,
expansionLineCount: diffContextExpansionLineCount,
hunkSeparators: 'line-info-basic',
Expand Down Expand Up @@ -3377,7 +3379,7 @@ export function ReviewCodeView({
return;
}

if (hasActiveTextSelection()) {
if (!commentOnLineClick || hasActiveTextSelection()) {
return;
}

Expand All @@ -3403,7 +3405,7 @@ export function ReviewCodeView({
return;
}

if (!range) {
if (!range || !commentOnLineClick) {
return;
}

Expand Down Expand Up @@ -3455,6 +3457,7 @@ export function ReviewCodeView({
[
bottomInset,
cancelPendingEmptyCommentDeletes,
commentOnLineClick,
createCommentForRange,
diffStyle,
isReadOnly,
Expand Down
5 changes: 5 additions & 0 deletions core/config/codiff-config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
"default": 13,
"description": "Font size in pixels used for diff and code rendering."
},
"commentOnLineClick": {
"type": "boolean",
"default": true,
"description": "Open a review comment draft when clicking or dragging across diff lines. The gutter comment button keeps working when this is false."
},
"copyCommentsOnClose": {
"type": "boolean",
"default": false,
Expand Down
1 change: 1 addition & 0 deletions core/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type CodiffSettings = {
claudeModel: string;
codeFontFamily: string;
codeFontSize: number;
commentOnLineClick: boolean;
copyCommentsOnClose: boolean;
diffStyle: CodiffDiffStyle;
editorCommand: string;
Expand Down
1 change: 1 addition & 0 deletions core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,7 @@ export type CodiffPreferences = {
claudeModel: string;
codeFontFamily: string;
codeFontSize: number;
commentOnLineClick: boolean;
copyCommentsOnClose: boolean;
diffStyle: CodiffDiffStyle;
editorCommand: string;
Expand Down
4 changes: 4 additions & 0 deletions electron/config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ const mergeConfig = (raw) => {
: defaults.settings.claudeModel,
codeFontFamily: normalizeCodeFontFamily(rawSettings.codeFontFamily),
codeFontSize: normalizeCodeFontSize(rawSettings.codeFontSize),
commentOnLineClick:
typeof rawSettings.commentOnLineClick === 'boolean'
? rawSettings.commentOnLineClick
: defaults.settings.commentOnLineClick,
copyCommentsOnClose:
typeof rawSettings.copyCommentsOnClose === 'boolean'
? rawSettings.copyCommentsOnClose
Expand Down