Skip to content

Commit 9403cee

Browse files
committed
make double click able to open a diff
1 parent 8c60ea0 commit 9403cee

File tree

2 files changed

+48
-19
lines changed

2 files changed

+48
-19
lines changed

src/components/FileItem.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export interface IFileItemProps {
3434
model: GitExtension;
3535
selected?: boolean;
3636
selectFile?: (file: Git.IStatusFile | null) => void;
37+
onDoubleClick?: () => void;
3738
}
3839

3940
export interface IGitMarkBoxProps {
@@ -95,7 +96,9 @@ export class FileItem extends React.Component<IFileItemProps> {
9596
})
9697
}
9798
onDoubleClick={() => {
98-
openListedFile(this.props.file, this.props.model);
99+
this.props.onDoubleClick
100+
? this.props.onDoubleClick()
101+
: openListedFile(this.props.file, this.props.model);
99102
}}
100103
title={`${this.props.file.to}${status}`}
101104
>

src/components/FileList.tsx

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
362362
model={this.props.model}
363363
selected={this._isSelectedFile(file)}
364364
selectFile={this.updateSelectedFile}
365+
onDoubleClick={this._onDoubleClickFactory(file, 'WORKING')}
365366
/>
366367
);
367368
})}
@@ -425,6 +426,7 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
425426
model={this.props.model}
426427
selected={this._isSelectedFile(file)}
427428
selectFile={this.updateSelectedFile}
429+
onDoubleClick={this._onDoubleClickFactory(file, 'WORKING')}
428430
/>
429431
);
430432
})}
@@ -491,6 +493,7 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
491493
>
492494
{files.map((file: Git.IStatusFile) => {
493495
let actions = null;
496+
let onDoubleClick = null;
494497
if (file.status === 'unstaged') {
495498
actions = (
496499
<React.Fragment>
@@ -505,8 +508,10 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
505508
{this._createDiffButton(file, 'WORKING')}
506509
</React.Fragment>
507510
);
511+
onDoubleClick = this._onDoubleClickFactory(file, 'WORKING');
508512
} else if (file.status === 'staged') {
509513
actions = this._createDiffButton(file, 'INDEX');
514+
onDoubleClick = this._onDoubleClickFactory(file, 'INDEX');
510515
}
511516

512517
return (
@@ -516,6 +521,7 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
516521
file={file}
517522
markBox={true}
518523
model={this.props.model}
524+
onDoubleClick={onDoubleClick}
519525
/>
520526
);
521527
})}
@@ -539,29 +545,49 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
539545
className={hiddenButtonStyle}
540546
iconName={'git-diff'}
541547
title={'Diff this file'}
542-
onClick={async () => {
543-
try {
544-
await openDiffView(
545-
file.to,
546-
this.props.model,
547-
{
548-
previousRef: { gitRef: 'HEAD' },
549-
currentRef: { specialRef: currentRef }
550-
},
551-
this.props.renderMime,
552-
!file.is_binary
553-
);
554-
} catch (reason) {
555-
console.error(
556-
`Fail to open diff view for ${file.to}.\n${reason}`
557-
);
558-
}
559-
}}
548+
onClick={this._openDiffViewFactory(file, currentRef)}
560549
/>
561550
)
562551
);
563552
}
564553

554+
private _openDiffViewFactory(
555+
file: Git.IStatusFile,
556+
currentRef: ISpecialRef['specialRef']
557+
) {
558+
const self = this;
559+
return genDiff;
560+
561+
async function genDiff() {
562+
try {
563+
await openDiffView(
564+
file.to,
565+
self.props.model,
566+
{
567+
previousRef: { gitRef: 'HEAD' },
568+
currentRef: { specialRef: currentRef }
569+
},
570+
self.props.renderMime,
571+
!file.is_binary
572+
);
573+
} catch (reason) {
574+
console.error(`Fail to open diff view for ${file.to}.\n${reason}`);
575+
}
576+
}
577+
}
578+
579+
private _onDoubleClickFactory(
580+
file: Git.IStatusFile,
581+
currentRef: ISpecialRef['specialRef']
582+
) {
583+
if (
584+
this.props.settings.composite['doubleClickDiff'] &&
585+
(isDiffSupported(file.to) || !file.is_binary)
586+
) {
587+
return this._openDiffViewFactory(file, currentRef);
588+
}
589+
}
590+
565591
private _contextMenuStaged: Menu;
566592
private _contextMenuUnstaged: Menu;
567593
private _contextMenuUntracked: Menu;

0 commit comments

Comments
 (0)