fix: Ctrl+W only closes the active tab, not all tabs
This commit is contained in:
parent
de265bb5a8
commit
0bafc358aa
@ -366,6 +366,7 @@ function App() {
|
|||||||
<Terminal
|
<Terminal
|
||||||
tabId={tab.id}
|
tabId={tab.id}
|
||||||
hostId={tab.hostId}
|
hostId={tab.hostId}
|
||||||
|
isActive={activeTabId === tab.id}
|
||||||
onConnectionChange={(connected) => handleConnectionChange(tab.id, connected)}
|
onConnectionChange={(connected) => handleConnectionChange(tab.id, connected)}
|
||||||
onShowCommandPalette={openCommandPalette}
|
onShowCommandPalette={openCommandPalette}
|
||||||
onToggleInfoPanel={() => setShowInfoPanel(!showInfoPanel)}
|
onToggleInfoPanel={() => setShowInfoPanel(!showInfoPanel)}
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import { WebglAddon } from '@xterm/addon-webgl';
|
|||||||
import '@xterm/xterm/css/xterm.css';
|
import '@xterm/xterm/css/xterm.css';
|
||||||
import { FiCommand, FiRefreshCw, FiInfo, FiFolder, FiActivity, FiZap } from 'react-icons/fi';
|
import { FiCommand, FiRefreshCw, FiInfo, FiFolder, FiActivity, FiZap } from 'react-icons/fi';
|
||||||
|
|
||||||
function Terminal({ tabId, hostId, onConnectionChange, onShowCommandPalette, onToggleInfoPanel, onOpenSFTP, showInfoPanel, onCloseTab }) {
|
function Terminal({ tabId, hostId, isActive, onConnectionChange, onShowCommandPalette, onToggleInfoPanel, onOpenSFTP, showInfoPanel, onCloseTab }) {
|
||||||
const containerRef = useRef(null);
|
const containerRef = useRef(null);
|
||||||
const terminalRef = useRef(null);
|
const terminalRef = useRef(null);
|
||||||
const xtermRef = useRef(null);
|
const xtermRef = useRef(null);
|
||||||
@ -32,6 +32,9 @@ function Terminal({ tabId, hostId, onConnectionChange, onShowCommandPalette, onT
|
|||||||
const onShowCommandPaletteRef = useRef(onShowCommandPalette);
|
const onShowCommandPaletteRef = useRef(onShowCommandPalette);
|
||||||
onShowCommandPaletteRef.current = onShowCommandPalette;
|
onShowCommandPaletteRef.current = onShowCommandPalette;
|
||||||
|
|
||||||
|
const isActiveRef = useRef(isActive);
|
||||||
|
isActiveRef.current = isActive;
|
||||||
|
|
||||||
const [connectionId, setConnectionId] = useState(null);
|
const [connectionId, setConnectionId] = useState(null);
|
||||||
const [isConnecting, setIsConnecting] = useState(false);
|
const [isConnecting, setIsConnecting] = useState(false);
|
||||||
const [error, setError] = useState(null);
|
const [error, setError] = useState(null);
|
||||||
@ -231,8 +234,13 @@ function Terminal({ tabId, hostId, onConnectionChange, onShowCommandPalette, onT
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 自定义按键处理 - 拦截 Ctrl+W 和 Ctrl+K
|
// 自定义按键处理 - 拦截 Ctrl+W 和 Ctrl+K(仅当前活动标签页响应)
|
||||||
term.attachCustomKeyEventHandler((e) => {
|
term.attachCustomKeyEventHandler((e) => {
|
||||||
|
// 只有活动标签页才响应快捷键
|
||||||
|
if (!isActiveRef.current) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Ctrl+W: 关闭当前标签页
|
// Ctrl+W: 关闭当前标签页
|
||||||
if ((e.ctrlKey || e.metaKey) && e.key === 'w') {
|
if ((e.ctrlKey || e.metaKey) && e.key === 'w') {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user