Skip to content

Commit cd207de

Browse files
committed
🐛 Prevent showing hints if input value is empty
1 parent 4ebee30 commit cd207de

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/components/Terminal.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ const Terminal = () => {
6565
const [inputVal, setInputVal] = useState("");
6666
const [cmdHistory, setCmdHistory] = useState<string[]>(["welcome"]);
6767
const [rerender, setRerender] = useState(false);
68+
const [hints, setHints] = useState<string[]>([]);
69+
const [pointer, setPointer] = useState(-1);
6870

6971
const handleChange = useCallback(
7072
(e: React.ChangeEvent<HTMLInputElement>) => {
@@ -100,8 +102,6 @@ const Terminal = () => {
100102
}, [containerRef]);
101103

102104
// Keyboard Press
103-
const [hints, setHints] = useState<string[]>([]);
104-
const [pointer, setPointer] = useState(-1);
105105
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
106106
setRerender(false);
107107
const ctrlI = e.ctrlKey && e.key.toLowerCase() === "i";
@@ -110,6 +110,8 @@ const Terminal = () => {
110110
// if Tab or Ctrl + I
111111
if (e.key === "Tab" || ctrlI) {
112112
e.preventDefault();
113+
if (!inputVal) return;
114+
113115
let hintsCmds: string[] = [];
114116
commands.forEach(({ cmd }) => {
115117
if (_.startsWith(cmd, inputVal)) {
@@ -168,6 +170,7 @@ const Terminal = () => {
168170
inputRef?.current?.blur();
169171
}
170172
};
173+
171174
// For caret position at the end
172175
useEffect(() => {
173176
const timer = setTimeout(() => {

0 commit comments

Comments
 (0)