Skip to content

Commit 6273bcf

Browse files
committed
feat: fix terminal focus when switching between multi terminal
1 parent 8698695 commit 6273bcf

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

CodeApp/Managers/TerminalInstance.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ class TerminalInstance: NSObject, WKScriptMessageHandler, WKNavigationDelegate,
5555
executeScript("document.getElementById('overlay').focus()")
5656
}
5757

58+
func focus() {
59+
executeScript("term.focus()")
60+
}
61+
5862
func sendInterrupt() {
5963
executeScript("sendInterrupt()")
6064
}

CodeApp/Managers/TerminalManager.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ class TerminalManager: ObservableObject {
170170
logger.info(
171171
"created terminal name: \(terminal.name, privacy: .public) id: \(terminal.id, privacy: .public)"
172172
)
173+
// Introduce delay to allow web view finishes loading before calling focus
174+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
175+
terminal.focus()
176+
}
173177
return terminal
174178
}
175179

@@ -288,6 +292,7 @@ class TerminalManager: ObservableObject {
288292
private func setActiveTerminalId(_ id: UUID?) {
289293
activeTerminalId = id
290294
syncRemoteTerminalId()
295+
activeTerminal?.focus()
291296
}
292297

293298
private func syncRemoteTerminalId() {

0 commit comments

Comments
 (0)