merogge/wip200777
Megan Rogge 2024-12-20 15:42:28 -06:00
parent f940e6aaad
commit 40547f07ec
No known key found for this signature in database
GPG Key ID: B8E497F5C2C8EDE8
3 changed files with 16 additions and 6 deletions

View File

@ -928,6 +928,7 @@ export type ITerminalProfileObject = ITerminalExecutable | ITerminalProfileSourc
export interface IShellIntegration {
readonly capabilities: ITerminalCapabilityStore;
readonly status: ShellIntegrationStatus;
updateCwd(newCwd: string): void;
readonly onDidChangeStatus: Event<ShellIntegrationStatus>;

View File

@ -439,7 +439,7 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
return true;
}
case 'Cwd': {
this._updateCwd(value);
this.updateCwd(value);
return true;
}
case 'IsWindows': {
@ -487,7 +487,7 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
}
}
private _updateCwd(value: string) {
updateCwd(value: string) {
value = sanitizeCwd(value);
this._createOrGetCwdDetection().updateCwd(value);
const commandDetection = this.capabilities.get(TerminalCapability.CommandDetection);
@ -518,7 +518,7 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
switch (key) {
case ITermOscPt.CurrentDir:
// Encountered: `OSC 1337 ; CurrentDir=<Cwd> ST`
this._updateCwd(value);
this.updateCwd(value);
return true;
}
}
@ -538,7 +538,7 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
case '9':
// Encountered `OSC 9 ; 9 ; <cwd> ST`
if (args.length) {
this._updateCwd(args[0]);
this.updateCwd(args[0]);
}
return true;
}
@ -560,7 +560,7 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
if (command.match(/^file:\/\/.*\//)) {
const uri = URI.parse(command);
if (uri.path && uri.path.length > 0) {
this._updateCwd(uri.path);
this.updateCwd(uri.path);
return true;
}
}

View File

@ -873,6 +873,12 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
return xterm;
}
private _setCwdForShellIntegration(): void {
if (this.shellLaunchConfig.attachPersistentProcess?.cwd) {
this.xterm?.shellIntegration.updateCwd(this.shellLaunchConfig.attachPersistentProcess?.cwd);
}
}
async runCommand(commandLine: string, shouldExecute: boolean): Promise<void> {
let commandDetection = this.capabilities.get(TerminalCapability.CommandDetection);
@ -884,6 +890,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
store.add(this.capabilities.onDidAddCapabilityType(e => {
if (e === TerminalCapability.CommandDetection) {
commandDetection = this.capabilities.get(TerminalCapability.CommandDetection);
this._setCwdForShellIntegration();
r();
}
}));
@ -892,6 +899,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
]);
store.dispose();
}
this._setCwdForShellIntegration();
// Determine whether to send ETX (ctrl+c) before running the command. This should always
// happen unless command detection can reliably say that a command is being entered and
@ -980,6 +988,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
}
this._register(xterm.shellIntegration.onDidChangeStatus(() => {
this._setCwdForShellIntegration();
if (this.hasFocus) {
this._setShellIntegrationContextKey();
} else {
@ -1395,7 +1404,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
break;
case ProcessPropertyType.InitialCwd:
this._initialCwd = value;
this._cwd = this._initialCwd;
this._cwd = this._cwd ?? this._initialCwd;
this._setTitle(this.title, TitleEventSource.Config);
this._icon = this._shellLaunchConfig.attachPersistentProcess?.icon || this._shellLaunchConfig.icon;
this._onIconChanged.fire({ instance: this, userInitiated: false });