mirror of
https://github.com/jkingsman/Remote-Terminal-for-MeshCore.git
synced 2026-07-07 02:11:22 +02:00
Refocus CLI textbox after command completion. Closes #164.
This commit is contained in:
@@ -13,6 +13,8 @@ export function ConsolePane({
|
|||||||
}) {
|
}) {
|
||||||
const [input, setInput] = useState('');
|
const [input, setInput] = useState('');
|
||||||
const outputRef = useRef<HTMLDivElement>(null);
|
const outputRef = useRef<HTMLDivElement>(null);
|
||||||
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
|
const prevLoadingRef = useRef(loading);
|
||||||
|
|
||||||
// Auto-scroll to bottom on new entries
|
// Auto-scroll to bottom on new entries
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -21,6 +23,14 @@ export function ConsolePane({
|
|||||||
}
|
}
|
||||||
}, [history]);
|
}, [history]);
|
||||||
|
|
||||||
|
// Refocus input after command completes
|
||||||
|
useEffect(() => {
|
||||||
|
if (prevLoadingRef.current && !loading) {
|
||||||
|
inputRef.current?.focus();
|
||||||
|
}
|
||||||
|
prevLoadingRef.current = loading;
|
||||||
|
}, [loading]);
|
||||||
|
|
||||||
const handleSubmit = useCallback(
|
const handleSubmit = useCallback(
|
||||||
async (e: FormEvent) => {
|
async (e: FormEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@@ -59,6 +69,7 @@ export function ConsolePane({
|
|||||||
</div>
|
</div>
|
||||||
<form onSubmit={handleSubmit} className="flex gap-2 p-2 border-t border-border">
|
<form onSubmit={handleSubmit} className="flex gap-2 p-2 border-t border-border">
|
||||||
<Input
|
<Input
|
||||||
|
ref={inputRef}
|
||||||
type="text"
|
type="text"
|
||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
name="console-input"
|
name="console-input"
|
||||||
|
|||||||
Reference in New Issue
Block a user