feat: auto-focus terminal when tab becomes active
This commit is contained in:
parent
9aaa1eaf07
commit
568ce93bf0
@ -36,6 +36,16 @@ function Terminal({ tabId, hostId, isActive, onConnectionChange, onShowCommandPa
|
||||
const isActiveRef = useRef(isActive);
|
||||
isActiveRef.current = isActive;
|
||||
|
||||
// 当标签页变为活动状态时,自动聚焦终端
|
||||
useEffect(() => {
|
||||
if (isActive && xtermRef.current) {
|
||||
// 短暂延迟确保 DOM 已更新
|
||||
setTimeout(() => {
|
||||
xtermRef.current?.focus();
|
||||
}, 50);
|
||||
}
|
||||
}, [isActive]);
|
||||
|
||||
const [connectionId, setConnectionId] = useState(null);
|
||||
const [isConnecting, setIsConnecting] = useState(false);
|
||||
const [error, setError] = useState(null);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user