From 589e01d2e73a3ccd2967651c1157f57024d953ba Mon Sep 17 00:00:00 2001 From: danthe1st Date: Sat, 8 Aug 2026 15:25:07 +0200 Subject: [PATCH] restore current working directory in terminal even if directory selected When the terminals in the terminal view were restored with a directory selected, all the terminals to restore were set to use the directory of the selection. With this change, the selection is only used for new terminals and not for ones that are restored. --- .../local/launcher/LocalLauncherDelegate.java | 6 ++++-- .../view/ui/internal/TerminalService.java | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/terminal/bundles/org.eclipse.terminal.connector.local/src/org/eclipse/terminal/connector/local/launcher/LocalLauncherDelegate.java b/terminal/bundles/org.eclipse.terminal.connector.local/src/org/eclipse/terminal/connector/local/launcher/LocalLauncherDelegate.java index 6ef0a48795f..8e638cd36e0 100644 --- a/terminal/bundles/org.eclipse.terminal.connector.local/src/org/eclipse/terminal/connector/local/launcher/LocalLauncherDelegate.java +++ b/terminal/bundles/org.eclipse.terminal.connector.local/src/org/eclipse/terminal/connector/local/launcher/LocalLauncherDelegate.java @@ -105,8 +105,10 @@ public CompletableFuture execute(Map properties) { properties.put(ITerminalsConnectorConstants.PROP_FORCE_NEW, Boolean.TRUE); } + boolean hadWorkingDirectoryBefore = properties + .containsKey(ITerminalsConnectorConstants.PROP_PROCESS_WORKING_DIR); // Initialize the local terminal working directory. - if (!properties.containsKey(ITerminalsConnectorConstants.PROP_PROCESS_WORKING_DIR)) { + if (!hadWorkingDirectoryBefore) { // By default, start the local terminal in the users home directory String initialCwd = IPreferenceKeys.getPreferences() .getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_INITIAL_CWD); @@ -213,7 +215,7 @@ public CompletableFuture execute(Map properties) { } } } - if (dir != null) { + if (!hadWorkingDirectoryBefore && dir != null) { properties.put(ITerminalsConnectorConstants.PROP_PROCESS_WORKING_DIR, dir); String basename = new Path(dir).lastSegment(); diff --git a/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/TerminalService.java b/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/TerminalService.java index a7ecbc39d2a..53ee1ca3fab 100644 --- a/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/TerminalService.java +++ b/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/TerminalService.java @@ -14,9 +14,11 @@ import java.util.HashMap; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; +import java.util.concurrent.atomic.AtomicReference; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; @@ -250,6 +252,7 @@ protected ITerminalConnector createTerminalConnector(Map propert public CompletableFuture openConsole(final Map properties) { Assert.isNotNull(properties); final boolean restoringView = fRestoringView; + AtomicReference> endOperation = new AtomicReference<>(null); return executeServiceOperation(properties, new TerminalServiceRunnable() { @Override public void run(TerminalViewId tvid, String title, ITerminalConnector connector, Object data) @@ -261,7 +264,14 @@ public void run(TerminalViewId tvid, String title, ITerminalConnector connector, fRestoringView = true; consoleViewManager.showConsoleView(tvid); fRestoringView = false; - doRun(tvid, title, connector, data); + + // To make sure that the terminals started by showConsoleView() are started first, + // we have to delay starting the current one with executeServiceOperation() + // (add the operation at the end of the queue) + endOperation.set(executeServiceOperation( + (tvid2, title2, connector2, data2) -> doRun(tvid, title, connector, data), tvid, title, + connector, data)); + } } @@ -294,7 +304,8 @@ private void doRun(TerminalViewId tvid, String title, ITerminalConnector connect console.setData("properties", properties); //$NON-NLS-1$ } } - }); + }).thenCompose(o -> Objects.>requireNonNullElse(endOperation.get(), + CompletableFuture.completedFuture(o))); } @Override