diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 191505dba..4b1afe32c 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -4,7 +4,7 @@ on: push: branches: '**' pull_request: - branches: [ main ] + branches: [ terminal-focus-fix-branch ] jobs: build: diff --git a/src/main/java/io/openliberty/tools/intellij/util/LibertyProjectUtil.java b/src/main/java/io/openliberty/tools/intellij/util/LibertyProjectUtil.java index 54629ceca..9ce4c5dc1 100644 --- a/src/main/java/io/openliberty/tools/intellij/util/LibertyProjectUtil.java +++ b/src/main/java/io/openliberty/tools/intellij/util/LibertyProjectUtil.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2020, 2022 IBM Corporation. + * Copyright (c) 2020, 2023 IBM Corporation. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at @@ -13,15 +13,19 @@ import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; +import com.intellij.openapi.wm.ToolWindow; import com.intellij.psi.PsiFile; import com.intellij.psi.search.FilenameIndex; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.terminal.JBTerminalWidget; +import com.intellij.ui.content.Content; +import com.intellij.ui.content.ContentManager; import com.sun.istack.Nullable; import io.openliberty.tools.intellij.LibertyModule; import io.openliberty.tools.intellij.LibertyModules; import io.openliberty.tools.intellij.LibertyProjectSettings; import org.jetbrains.plugins.terminal.ShellTerminalWidget; +import org.jetbrains.plugins.terminal.TerminalToolWindowManager; import org.jetbrains.plugins.terminal.TerminalView; import org.xml.sax.SAXException; @@ -149,6 +153,26 @@ public static ShellTerminalWidget getTerminalWidget(Project project, LibertyModu TerminalView terminalView = TerminalView.getInstance(project); // look for existing terminal tab ShellTerminalWidget widget = getTerminalWidget(libertyModule, terminalView); + TerminalToolWindowManager manager = TerminalToolWindowManager.getInstance(project); + ToolWindow toolWindow = manager.getToolWindow(); + String widgetName = libertyModule.getName(); + + ContentManager contentManager = toolWindow.getContentManager(); + Content[] contents = contentManager.getContents(); + + int index = 0; + for (int i = 0; i < contents.length; i++) { + String displayName = contents[i].getDisplayName(); + if (widgetName.equals(displayName)) { + index = i; + break; + } + } + if (contents.length > 0) { + Content terminalContent = contents[index]; + contentManager.setSelectedContent(terminalContent); + terminalContent.getComponent().requestFocus(); + } if (widget == null && createWidget) { // create a new terminal tab ShellTerminalWidget newTerminal = terminalView.createLocalShellWidget(project.getBasePath(), libertyModule.getName(), true);