Skip to content

Commit cf4b018

Browse files
committed
feat(command-history): add option for min chars to save to history else ignore
1 parent 71b89b4 commit cf4b018

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

electron/renderer/hooks/command-history.tsx

+14-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,16 @@ export interface CommandHistory {
5050
handleOnChange: (event: ChangeEvent<HTMLInputElement>) => void;
5151
}
5252

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+
5463
const store = useCommandHistoryStore(
5564
// Technically, our state reducer is returning a new object
5665
// each time although the properties are the same.
@@ -89,7 +98,9 @@ export const useCommandHistory = (): CommandHistory => {
8998
store.navigateHistory('down');
9099
} else if (event.code === 'Enter') {
91100
if (!isBlank(command)) {
92-
store.addCommand(command);
101+
if (command.length >= minChars) {
102+
store.addCommand(command);
103+
}
93104
store.setInput('');
94105
store.setIndex(-1);
95106
}
@@ -99,7 +110,7 @@ export const useCommandHistory = (): CommandHistory => {
99110
store.setInput(event.currentTarget.value);
100111
},
101112
};
102-
}, [store]);
113+
}, [store, minChars]);
103114

104115
return api;
105116
};

0 commit comments

Comments
 (0)