new tab inherits cwd
This commit is contained in:
@@ -156,7 +156,10 @@ public final class Compositor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void newTab() {
|
public void newTab() {
|
||||||
tabs.add(new Tab(config, metrics));
|
// Open the new tab in the currently active pane's working directory, so it lands where the
|
||||||
|
// user currently is rather than always in home.
|
||||||
|
String workingDirectory = isEmpty() ? null : currentTab().activePane().currentWorkingDirectory();
|
||||||
|
tabs.add(new Tab(config, metrics, workingDirectory));
|
||||||
currentTabIndex = tabs.size() - 1;
|
currentTabIndex = tabs.size() - 1;
|
||||||
layoutVersion++;
|
layoutVersion++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ final class Tab implements AutoCloseable {
|
|||||||
private final List<TerminalPane> floating = new ArrayList<>();
|
private final List<TerminalPane> floating = new ArrayList<>();
|
||||||
private boolean floatingVisible;
|
private boolean floatingVisible;
|
||||||
private TerminalPane active;
|
private TerminalPane active;
|
||||||
|
private final String initialWorkingDirectory;
|
||||||
// The floating pane to re-focus when the group is shown again, and to prefer when promoting
|
// The floating pane to re-focus when the group is shown again, and to prefer when promoting
|
||||||
// after the last tiled pane closes.
|
// after the last tiled pane closes.
|
||||||
private TerminalPane lastFocusedFloating;
|
private TerminalPane lastFocusedFloating;
|
||||||
@@ -37,10 +38,19 @@ final class Tab implements AutoCloseable {
|
|||||||
private final AtomicLong contentVersion = new AtomicLong();
|
private final AtomicLong contentVersion = new AtomicLong();
|
||||||
|
|
||||||
Tab(AppConfig config, TerminalMetrics metrics) {
|
Tab(AppConfig config, TerminalMetrics metrics) {
|
||||||
|
this(config, metrics, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a tab whose first pane starts in {@code initialWorkingDirectory} (e.g. the cwd of the
|
||||||
|
* pane that was active when this tab was opened), or the user's home when {@code null}.
|
||||||
|
*/
|
||||||
|
Tab(AppConfig config, TerminalMetrics metrics, String initialWorkingDirectory) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.metrics = metrics;
|
this.metrics = metrics;
|
||||||
this.lastWidth = config.windowWidth();
|
this.lastWidth = config.windowWidth();
|
||||||
this.lastHeight = config.windowHeight();
|
this.lastHeight = config.windowHeight();
|
||||||
|
this.initialWorkingDirectory = initialWorkingDirectory;
|
||||||
TerminalPane first = openPane(false);
|
TerminalPane first = openPane(false);
|
||||||
tiled.add(first);
|
tiled.add(first);
|
||||||
active = first;
|
active = first;
|
||||||
@@ -309,8 +319,9 @@ final class Tab implements AutoCloseable {
|
|||||||
heightPx = availHeight;
|
heightPx = availHeight;
|
||||||
}
|
}
|
||||||
// Open the new pane in the active pane's working directory, so a split/new pane lands
|
// Open the new pane in the active pane's working directory, so a split/new pane lands
|
||||||
// where the user currently is. null (no active pane yet, or cwd unknown) falls back to home.
|
// where the user currently is. With no active pane yet (the tab's first pane), fall back to
|
||||||
String workingDirectory = active != null ? active.currentWorkingDirectory() : null;
|
// the directory this tab was opened in. null (cwd unknown) falls back to home downstream.
|
||||||
|
String workingDirectory = active != null ? active.currentWorkingDirectory() : initialWorkingDirectory;
|
||||||
return TerminalPane.create(config, metrics, this::markContentChanged, widthPx, heightPx, workingDirectory);
|
return TerminalPane.create(config, metrics, this::markContentChanged, widthPx, heightPx, workingDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user