@@ -14,11 +14,14 @@ import { openFile } from '../lib/open-file'
1414import {
1515 isSafeFileExtension ,
1616 CopyFilePathLabel ,
17+ CopyRelativeFilePathLabel ,
18+ CopySelectedPathsLabel ,
19+ CopySelectedRelativePathsLabel ,
1720 DefaultEditorLabel ,
1821 RevealInFileManagerLabel ,
1922 OpenWithDefaultProgramLabel ,
20- CopyRelativeFilePathLabel ,
2123} from '../lib/context-menu'
24+ import { EOL } from 'os'
2225import { ThrottledScheduler } from '../lib/throttled-scheduler'
2326
2427import { Dispatcher } from '../dispatcher'
@@ -97,6 +100,7 @@ interface ISelectedCommitsProps {
97100
98101interface ISelectedCommitsState {
99102 readonly isExpanded : boolean
103+ readonly selectedFiles : ReadonlyArray < CommittedFileChange >
100104}
101105
102106/** The History component. Contains the commit list, commit summary, and diff. */
@@ -111,11 +115,17 @@ export class SelectedCommits extends React.Component<
111115
112116 this . state = {
113117 isExpanded : false ,
118+ selectedFiles : [ ] ,
114119 }
115120 }
116121
117- private onFileSelected = ( file : CommittedFileChange ) => {
118- this . props . dispatcher . changeFileSelection ( this . props . repository , file )
122+ private onFileSelectionChanged = (
123+ files : ReadonlyArray < CommittedFileChange >
124+ ) => {
125+ this . setState ( { selectedFiles : files } )
126+ if ( files . length === 1 ) {
127+ this . props . dispatcher . changeFileSelection ( this . props . repository , files [ 0 ] )
128+ }
119129 }
120130
121131 private onRowDoubleClick = ( row : number ) => {
@@ -131,9 +141,7 @@ export class SelectedCommits extends React.Component<
131141 const nextValue = nextProps . selectedCommits . map ( c => c . sha ) . join ( '' )
132142
133143 if ( currentValue !== nextValue ) {
134- if ( this . state . isExpanded ) {
135- this . setState ( { isExpanded : false } )
136- }
144+ this . setState ( { isExpanded : false , selectedFiles : [ ] } )
137145 }
138146 }
139147
@@ -266,8 +274,8 @@ export class SelectedCommits extends React.Component<
266274 { this . renderFileHeader ( ) }
267275 < FileList
268276 files = { files }
269- onSelectedFileChanged = { this . onFileSelected }
270- selectedFile = { this . props . selectedFile }
277+ onSelectionChanged = { this . onFileSelectionChanged }
278+ selectedFiles = { this . state . selectedFiles }
271279 availableWidth = { availableWidth }
272280 onContextMenu = { this . onContextMenu }
273281 onRowDoubleClick = { this . onRowDoubleClick }
@@ -404,6 +412,42 @@ export class SelectedCommits extends React.Component<
404412 ? `Open in ${ externalEditorLabel } `
405413 : DefaultEditorLabel
406414
415+ const { selectedFiles } = this . state
416+ const isMultiSelect =
417+ selectedFiles . length > 1 && selectedFiles . some ( f => f . path === file . path )
418+ const filesToCopy = isMultiSelect ? selectedFiles : [ file ]
419+
420+ const copyPathItems : ReadonlyArray < IMenuItem > =
421+ filesToCopy . length === 1
422+ ? [
423+ {
424+ label : CopyFilePathLabel ,
425+ action : ( ) => clipboard . writeText ( fullPath ) ,
426+ } ,
427+ {
428+ label : CopyRelativeFilePathLabel ,
429+ action : ( ) => clipboard . writeText ( Path . normalize ( file . path ) ) ,
430+ } ,
431+ ]
432+ : [
433+ {
434+ label : CopySelectedPathsLabel ,
435+ action : ( ) =>
436+ clipboard . writeText (
437+ filesToCopy
438+ . map ( f => Path . join ( repository . path , f . path ) )
439+ . join ( EOL )
440+ ) ,
441+ } ,
442+ {
443+ label : CopySelectedRelativePathsLabel ,
444+ action : ( ) =>
445+ clipboard . writeText (
446+ filesToCopy . map ( f => Path . normalize ( f . path ) ) . join ( EOL )
447+ ) ,
448+ } ,
449+ ]
450+
407451 const items : IMenuItem [ ] = [
408452 {
409453 label : RevealInFileManagerLabel ,
@@ -421,14 +465,7 @@ export class SelectedCommits extends React.Component<
421465 enabled : isSafeExtension && fileExistsOnDisk ,
422466 } ,
423467 { type : 'separator' } ,
424- {
425- label : CopyFilePathLabel ,
426- action : ( ) => clipboard . writeText ( fullPath ) ,
427- } ,
428- {
429- label : CopyRelativeFilePathLabel ,
430- action : ( ) => clipboard . writeText ( Path . normalize ( file . path ) ) ,
431- } ,
468+ ...copyPathItems ,
432469 { type : 'separator' } ,
433470 ]
434471
0 commit comments