(props: Props)
| 54 | type BooleanOptions = Extract<Unionize<Options>, {v: boolean}>['k']; |
| 55 | |
| 56 | export function DiffOptionsControl(props: Props) { |
| 57 | const {options, updateOptions, isVisible, setIsVisible} = props; |
| 58 | const maxDiffWidth = options.maxDiffWidth ?? props.defaultMaxDiffWidth; |
| 59 | |
| 60 | const togglePopup = () => { |
| 61 | setIsVisible(!isVisible); |
| 62 | }; |
| 63 | const toggleField = (k: BooleanOptions) => () => { |
| 64 | updateOptions(options => ({[k]: !options[k]})); |
| 65 | }; |
| 66 | const setUnifiedContext: React.ChangeEventHandler<HTMLInputElement> = e => { |
| 67 | updateOptions({unified: e.currentTarget.valueAsNumber}); |
| 68 | }; |
| 69 | const changeDiffAlgorithm: React.ChangeEventHandler<HTMLSelectElement> = e => { |
| 70 | updateOptions({diffAlgorithm: e.currentTarget.value as DiffAlgorithm}); |
| 71 | }; |
| 72 | const changeMaxDiffWidth: React.ChangeEventHandler<HTMLInputElement> = e => { |
| 73 | updateOptions({maxDiffWidth: e.currentTarget.valueAsNumber}); |
| 74 | }; |
| 75 | |
| 76 | React.useEffect(() => { |
| 77 | const handleKeydown = (e: KeyboardEvent) => { |
| 78 | if (!isLegitKeypress(e)) return; |
| 79 | if (e.code == 'KeyW') { |
| 80 | updateOptions(options => ({ignoreAllSpace: !options.ignoreAllSpace})); |
| 81 | } else if (e.code == 'KeyB') { |
| 82 | updateOptions(options => ({ignoreSpaceChange: !options.ignoreSpaceChange})); |
| 83 | } |
| 84 | }; |
| 85 | document.addEventListener('keydown', handleKeydown); |
| 86 | return () => { |
| 87 | document.removeEventListener('keydown', handleKeydown); |
| 88 | }; |
| 89 | }, [options, updateOptions]); |
| 90 | |
| 91 | const diffOptsStr = gitDiffOptionsToFlags(options).join(' '); |
| 92 | |
| 93 | return ( |
| 94 | <> |
| 95 | <button style={gearStyle} onClick={togglePopup}> |
| 96 | ⚙ |
| 97 | </button> |
| 98 | {isVisible ? ( |
| 99 | <> |
| 100 | <PageCover onClick={togglePopup} /> |
| 101 | <div style={popupStyle}> |
| 102 | <button style={closeButtonStyle} onClick={togglePopup}> |
| 103 | ✕ |
| 104 | </button> |
| 105 | <table> |
| 106 | <tbody> |
| 107 | <tr> |
| 108 | <td style={{textAlign: 'right', verticalAlign: 'top'}} rowSpan={3}> |
| 109 | Whitespace: |
| 110 | </td> |
| 111 | <td> |
| 112 | <input |
| 113 | type="checkbox" |
nothing calls this directly
no test coverage detected