Commit cf4b018 1 parent 71b89b4 commit cf4b018 Copy full SHA for cf4b018
File tree 1 file changed +14
-3
lines changed
1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -50,7 +50,16 @@ export interface CommandHistory {
50
50
handleOnChange : ( event : ChangeEvent < HTMLInputElement > ) => void ;
51
51
}
52
52
53
- export const useCommandHistory = ( ) : CommandHistory => {
53
+ export const useCommandHistory = ( options ?: {
54
+ /**
55
+ * The minimum number of characters in a command to add it to the history.
56
+ * Anything less is not added.
57
+ * Default is 3.
58
+ */
59
+ minChars ?: number ;
60
+ } ) : CommandHistory => {
61
+ const minChars = options ?. minChars ?? 3 ;
62
+
54
63
const store = useCommandHistoryStore (
55
64
// Technically, our state reducer is returning a new object
56
65
// each time although the properties are the same.
@@ -89,7 +98,9 @@ export const useCommandHistory = (): CommandHistory => {
89
98
store . navigateHistory ( 'down' ) ;
90
99
} else if ( event . code === 'Enter' ) {
91
100
if ( ! isBlank ( command ) ) {
92
- store . addCommand ( command ) ;
101
+ if ( command . length >= minChars ) {
102
+ store . addCommand ( command ) ;
103
+ }
93
104
store . setInput ( '' ) ;
94
105
store . setIndex ( - 1 ) ;
95
106
}
@@ -99,7 +110,7 @@ export const useCommandHistory = (): CommandHistory => {
99
110
store . setInput ( event . currentTarget . value ) ;
100
111
} ,
101
112
} ;
102
- } , [ store ] ) ;
113
+ } , [ store , minChars ] ) ;
103
114
104
115
return api ;
105
116
} ;
You can’t perform that action at this time.
0 commit comments