File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed
Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -62,8 +62,12 @@ export function ButtonMapper({
6262
6363 const [ target , setTarget ] = useState ( /** @type {[string, keyof Mapping]|null } */ ( null ) ) ;
6464 useEffect ( ( ) => {
65+ if ( ! target ) {
66+ return ;
67+ }
6568 return waitForGamepadInput ( padInput => {
66- if ( ! target ) {
69+ setTarget ( null ) ;
70+ if ( ! padInput ) {
6771 return ;
6872 }
6973 setNewMappings ( ( /** @type {Mappings } */ m ) => {
@@ -81,7 +85,6 @@ export function ButtonMapper({
8185 } ;
8286 return updated ;
8387 } ) ;
84- setTarget ( null ) ;
8588 } ) ;
8689 } , [ target , setTarget , setNewMappings ] ) ;
8790
Original file line number Diff line number Diff line change @@ -257,7 +257,7 @@ function ignoreDeadzone(val) {
257257}
258258
259259/**
260- * @param {function(PadInput): void } callback
260+ * @param {function(PadInput|null ): void } callback
261261 * @returns {function(): void } a cancel/cleanup function
262262 */
263263export function waitForGamepadInput ( callback ) {
@@ -290,8 +290,18 @@ export function waitForGamepadInput(callback) {
290290 }
291291 const interval = setInterval ( findPressedInput , 100 ) ;
292292
293+ /** @type {function(KeyboardEvent): void } */
294+ const cancelHandler = e => {
295+ if ( e . key === 'Escape' ) {
296+ e . preventDefault ( ) ;
297+ callback ( null ) ;
298+ }
299+ }
300+ document . addEventListener ( 'keydown' , cancelHandler ) ;
301+
293302 return function cleanup ( ) {
294303 clearInterval ( interval ) ;
304+ document . removeEventListener ( 'keydown' , cancelHandler ) ;
295305 } ;
296306}
297307
You can’t perform that action at this time.
0 commit comments