-
-
Notifications
You must be signed in to change notification settings - Fork 241
Fix/ windows terminal focus #459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
207f19c
41d571f
2ce453f
52a13aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ type UseTerminalSessionOptions = { | |
| activeWorkspace: WorkspaceInfo | null; | ||
| activeTerminalId: string | null; | ||
| isVisible: boolean; | ||
| focusRequestVersion: number; | ||
| onDebug?: (entry: DebugEntry) => void; | ||
| onSessionExit?: (workspaceId: string, terminalId: string) => void; | ||
| }; | ||
|
|
@@ -114,6 +115,7 @@ export function useTerminalSession({ | |
| activeWorkspace, | ||
| activeTerminalId, | ||
| isVisible, | ||
| focusRequestVersion, | ||
| onDebug, | ||
| onSessionExit, | ||
| }: UseTerminalSessionOptions): TerminalSessionState { | ||
|
|
@@ -127,6 +129,7 @@ export function useTerminalSession({ | |
| const renderedKeyRef = useRef<string | null>(null); | ||
| const activeWorkspaceRef = useRef<WorkspaceInfo | null>(null); | ||
| const activeTerminalIdRef = useRef<string | null>(null); | ||
| const pendingFocusRef = useRef(false); | ||
| const [status, setStatus] = useState<TerminalStatus>("idle"); | ||
| const [message, setMessage] = useState("Open a terminal to start a session."); | ||
| const [hasSession, setHasSession] = useState(false); | ||
|
|
@@ -165,15 +168,23 @@ export function useTerminalSession({ | |
| terminalRef.current?.write(data); | ||
| }, []); | ||
|
|
||
| const focusTerminalIfRequested = useCallback(() => { | ||
| if (!pendingFocusRef.current) { | ||
| return; | ||
| } | ||
| pendingFocusRef.current = false; | ||
| terminalRef.current?.focus(); | ||
| }, []); | ||
|
|
||
| const refreshTerminal = useCallback(() => { | ||
| const terminal = terminalRef.current; | ||
| if (!terminal) { | ||
| return; | ||
| } | ||
| const lastRow = Math.max(0, terminal.rows - 1); | ||
| terminal.refresh(0, lastRow); | ||
| terminal.focus(); | ||
| }, []); | ||
| focusTerminalIfRequested(); | ||
| }, [focusTerminalIfRequested]); | ||
|
|
||
| const syncActiveBuffer = useCallback( | ||
| (key: string) => { | ||
|
|
@@ -353,6 +364,14 @@ export function useTerminalSession({ | |
| sessionResetCounter, | ||
| ]); | ||
|
|
||
| useEffect(() => { | ||
| if (!isVisible || focusRequestVersion === 0) { | ||
| return; | ||
| } | ||
| pendingFocusRef.current = true; | ||
| focusTerminalIfRequested(); | ||
|
Comment on lines
+368
to
+372
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This effect treats Useful? React with 👍 / 👎. |
||
| }, [focusRequestVersion, focusTerminalIfRequested, isVisible]); | ||
|
|
||
| useEffect(() => { | ||
| if (!isVisible || !activeKey || !terminalRef.current || !fitAddonRef.current) { | ||
| return; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refreshTerminalno longer focuses by default, so opening the panel now depends on an explicitrequestTerminalFocus()call. The keyboard shortcut path still goes throughusePanelShortcuts->useLayoutController-> rawhandleToggleTerminal(no focus request), so opening terminal via the configured shortcut leaves focus in the previous element and users cannot type until they click the terminal.Useful? React with 👍 / 👎.