@@ -8,19 +8,20 @@ import {isLegitKeypress} from './file_diff';
88import { ImageDiffMode } from './ImageDiffModeSelector' ;
99import { filePairDisplayName } from './utils' ;
1010import { DiffOptionsControl } from './DiffOptions' ;
11+ import { KeyboardShortcuts } from './codediff/KeyboardShortcuts' ;
1112
1213declare const pairs : FilePair [ ] ;
1314declare const initialIdx : number ;
1415
1516type Props = RouteComponentProps < { index ?: string } > ;
1617
17- const PDIFF_MODES : PerceptualDiffMode [ ] = [ 'off' , 'bbox' , 'pixels' ] ;
18-
1918// Webdiff application root.
2019export function Root ( props : Props ) {
2120 const [ pdiffMode , setPDiffMode ] = React . useState < PerceptualDiffMode > ( 'off' ) ;
2221 const [ imageDiffMode , setImageDiffMode ] = React . useState < ImageDiffMode > ( 'side-by-side' ) ;
2322 const [ diffOptions , setDiffOptions ] = React . useState < Partial < DiffOptions > > ( { } ) ;
23+ const [ showKeyboardHelp , setShowKeyboardHelp ] = React . useState ( false ) ;
24+ const [ showOptions , setShowOptions ] = React . useState ( false ) ;
2425
2526 const history = useHistory ( ) ;
2627 const selectIndex = React . useCallback (
@@ -48,31 +49,43 @@ export function Root(props: Props) {
4849 if ( idx < pairs . length - 1 ) {
4950 selectIndex ( idx + 1 ) ;
5051 }
51- } else if ( e . code == 'KeyS' ) {
52- setImageDiffMode ( 'side-by-side' ) ;
53- } else if ( e . code == 'KeyB ') {
54- setImageDiffMode ( 'blink' ) ;
55- } else if ( e . code == 'KeyP ') {
56- setPDiffMode ( PDIFF_MODES [ ( PDIFF_MODES . indexOf ( pdiffMode ) + 1 ) % 3 ] ) ;
52+ } else if ( e . code === 'Slash' && e . shiftKey ) {
53+ setShowKeyboardHelp ( val => ! val ) ;
54+ } else if ( e . code === 'Escape ') {
55+ setShowKeyboardHelp ( false ) ;
56+ } else if ( e . code === 'Period ') {
57+ setShowOptions ( val => ! val ) ;
5758 }
5859 } ;
5960 document . addEventListener ( 'keydown' , handleKeydown ) ;
6061 return ( ) => {
6162 document . removeEventListener ( 'keydown' , handleKeydown ) ;
6263 } ;
63- } , [ idx , pdiffMode , selectIndex , setImageDiffMode , setPDiffMode ] ) ;
64+ } , [ idx , selectIndex ] ) ;
6465
6566 return (
6667 < div >
67- < DiffOptionsControl options = { diffOptions } setOptions = { setDiffOptions } />
68+ < DiffOptionsControl
69+ options = { diffOptions }
70+ setOptions = { setDiffOptions }
71+ isVisible = { showOptions }
72+ setIsVisible = { setShowOptions }
73+ />
6874 < FileSelector selectedFileIndex = { idx } filePairs = { pairs } fileChangeHandler = { selectIndex } />
75+ { showKeyboardHelp ? (
76+ < KeyboardShortcuts
77+ onClose = { ( ) => {
78+ setShowKeyboardHelp ( false ) ;
79+ } }
80+ />
81+ ) : null }
6982 < DiffView
7083 key = { `diff-${ idx } ` }
7184 thinFilePair = { filePair }
7285 imageDiffMode = { imageDiffMode }
7386 pdiffMode = { pdiffMode }
7487 diffOptions = { diffOptions }
75- changeImageDiffModeHandler = { setImageDiffMode }
88+ changeImageDiffMode = { setImageDiffMode }
7689 changePDiffMode = { setPDiffMode }
7790 changeDiffOptions = { setDiffOptions }
7891 />
0 commit comments