@@ -5,32 +5,44 @@ import type {
5
5
KeyboardEventHandler ,
6
6
ReactNode ,
7
7
} from 'react' ;
8
- import { useCallback } from 'react' ;
8
+ import { useCallback , useState } from 'react' ;
9
9
import { isEmpty } from '../../../common/string/string.utils.js' ;
10
10
import { useCommandHistory } from '../../hooks/command-history.jsx' ;
11
11
import { runInBackground } from '../../lib/async/run-in-background.js' ;
12
12
13
13
export const GameCommandInput : React . FC = ( ) : ReactNode => {
14
14
const { input, handleKeyDown, handleOnChange } = useCommandHistory ( ) ;
15
+ const [ lastCommand , setLastCommand ] = useState < string > ( ) ;
15
16
16
17
const onKeyDown = useCallback < KeyboardEventHandler < HTMLInputElement > > (
17
18
( event : KeyboardEvent < HTMLInputElement > ) => {
18
19
// Handle any history navigation.
19
20
handleKeyDown ( event ) ;
20
21
// Handle the "Enter" key to submit command to game.
21
- const command = event . currentTarget . value ;
22
- if ( event . code === 'Enter' && ! isEmpty ( command ) ) {
23
- runInBackground ( async ( ) => {
24
- await window . api . sendCommand ( command ) ;
25
- } ) ;
22
+ if ( event . code === 'Enter' ) {
23
+ const command = event . currentTarget . value ;
24
+ // <Cmd>+<Enter> = perform last command
25
+ if ( event . metaKey && ! isEmpty ( lastCommand ) ) {
26
+ runInBackground ( async ( ) => {
27
+ await window . api . sendCommand ( lastCommand ) ;
28
+ } ) ;
29
+ }
30
+ // <Enter> = perform new command
31
+ else if ( ! isEmpty ( command ) ) {
32
+ setLastCommand ( command ) ;
33
+ runInBackground ( async ( ) => {
34
+ await window . api . sendCommand ( command ) ;
35
+ } ) ;
36
+ }
26
37
}
27
38
} ,
28
- [ handleKeyDown ]
39
+ [ handleKeyDown , lastCommand ]
29
40
) ;
30
41
31
42
const onChange = useCallback (
32
43
( event : ChangeEvent < HTMLInputElement > ) => {
33
44
// Sync the input value with the command history.
45
+ // Otherwise you don't see what you type into the box.
34
46
handleOnChange ( event ) ;
35
47
} ,
36
48
[ handleOnChange ]
@@ -42,6 +54,10 @@ export const GameCommandInput: React.FC = (): ReactNode => {
42
54
value = { input }
43
55
compressed = { true }
44
56
fullWidth = { true }
57
+ autoFocus = { true }
58
+ autoCorrect = "off"
59
+ autoCapitalize = "off"
60
+ autoComplete = "off"
45
61
prepend = { < EuiIcon type = "arrowRight" size = "s" color = "primary" /> }
46
62
tabIndex = { 0 }
47
63
onKeyDown = { onKeyDown }
0 commit comments