Skip to content

Commit d1ad717

Browse files
authored
Merge pull request microsoft#259332 from microsoft/tyriar/259326
Restore alt+left/right keybinding to switch terminal pane
2 parents 05201e6 + 6dda4e5 commit d1ad717

File tree

6 files changed

+25
-14
lines changed

6 files changed

+25
-14
lines changed

src/vs/workbench/contrib/terminal/browser/terminalActions.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,9 @@ export function registerTerminalActions() {
383383
primary: KeyMod.Alt | KeyMod.CtrlCmd | KeyCode.LeftArrow,
384384
secondary: [KeyMod.Alt | KeyMod.CtrlCmd | KeyCode.UpArrow]
385385
},
386-
when: TerminalContextKeys.focus,
387-
weight: KeybindingWeight.WorkbenchContrib
386+
when: ContextKeyExpr.and(TerminalContextKeys.focus, TerminalContextKeys.splitTerminalActive),
387+
// Should win over send sequence commands https://github.com/microsoft/vscode/issues/259326
388+
weight: KeybindingWeight.WorkbenchContrib + 1
388389
},
389390
precondition: sharedWhenClause.terminalAvailable,
390391
run: async (c) => {
@@ -403,8 +404,9 @@ export function registerTerminalActions() {
403404
primary: KeyMod.Alt | KeyMod.CtrlCmd | KeyCode.RightArrow,
404405
secondary: [KeyMod.Alt | KeyMod.CtrlCmd | KeyCode.DownArrow]
405406
},
406-
when: TerminalContextKeys.focus,
407-
weight: KeybindingWeight.WorkbenchContrib
407+
when: ContextKeyExpr.and(TerminalContextKeys.focus, TerminalContextKeys.splitTerminalActive),
408+
// Should win over send sequence commands https://github.com/microsoft/vscode/issues/259326
409+
weight: KeybindingWeight.WorkbenchContrib + 1
408410
},
409411
precondition: sharedWhenClause.terminalAvailable,
410412
run: async (c) => {

src/vs/workbench/contrib/terminal/browser/terminalGroupService.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { timeout } from '../../../../base/common/async.js';
88
import { Emitter, Event } from '../../../../base/common/event.js';
99
import { Disposable } from '../../../../base/common/lifecycle.js';
1010
import { URI } from '../../../../base/common/uri.js';
11-
import { IContextKey, IContextKeyService } from '../../../../platform/contextkey/common/contextkey.js';
11+
import { IContextKeyService } from '../../../../platform/contextkey/common/contextkey.js';
1212
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
1313
import { IShellLaunchConfig } from '../../../../platform/terminal/common/terminal.js';
1414
import { IViewDescriptorService } from '../../../common/views.js';
@@ -33,8 +33,6 @@ export class TerminalGroupService extends Disposable implements ITerminalGroupSe
3333

3434
lastAccessedMenu: 'inline-tab' | 'tab-list' = 'inline-tab';
3535

36-
private _terminalGroupCountContextKey: IContextKey<number>;
37-
3836
private _container: HTMLElement | undefined;
3937

4038
private _isQuickInputOpened: boolean = false;
@@ -71,10 +69,16 @@ export class TerminalGroupService extends Disposable implements ITerminalGroupSe
7169
) {
7270
super();
7371

74-
this._terminalGroupCountContextKey = TerminalContextKeys.groupCount.bindTo(this._contextKeyService);
72+
const terminalGroupCountContextKey = TerminalContextKeys.groupCount.bindTo(this._contextKeyService);
73+
this._register(Event.runAndSubscribe(this.onDidChangeGroups, () => terminalGroupCountContextKey.set(this.groups.length)));
74+
75+
const splitTerminalActiveContextKey = TerminalContextKeys.splitTerminalActive.bindTo(this._contextKeyService);
76+
this._register(Event.runAndSubscribe(this.onDidFocusInstance, () => {
77+
const activeInstance = this.activeInstance;
78+
splitTerminalActiveContextKey.set(activeInstance ? this.instanceIsSplit(activeInstance) : false);
79+
}));
7580

7681
this._register(this.onDidDisposeGroup(group => this._removeGroup(group)));
77-
this._register(this.onDidChangeGroups(() => this._terminalGroupCountContextKey.set(this.groups.length)));
7882
this._register(Event.any(this.onDidChangeActiveGroup, this.onDidChangeInstances)(() => this.updateVisibility()));
7983
this._register(this._quickInputService.onShow(() => this._isQuickInputOpened = true));
8084
this._register(this._quickInputService.onHide(() => this._isQuickInputOpened = false));

src/vs/workbench/contrib/terminal/browser/terminalMenus.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ export function setupTerminalMenus(): void {
602602
id: TerminalCommandId.Unsplit,
603603
title: terminalStrings.unsplit.value
604604
},
605-
when: ContextKeyExpr.and(TerminalContextKeys.tabsSingularSelection, TerminalContextKeys.splitTerminal),
605+
when: ContextKeyExpr.and(TerminalContextKeys.tabsSingularSelection, TerminalContextKeys.splitTerminalTabFocused),
606606
group: ContextMenuGroup.Config
607607
}
608608
},

src/vs/workbench/contrib/terminal/browser/terminalTabsList.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ export class TerminalTabList extends WorkbenchList<ITerminalInstance> {
193193
}));
194194

195195
this._terminalTabsSingleSelectedContextKey = TerminalContextKeys.tabsSingularSelection.bindTo(contextKeyService);
196-
this._isSplitContextKey = TerminalContextKeys.splitTerminal.bindTo(contextKeyService);
196+
this._isSplitContextKey = TerminalContextKeys.splitTerminalTabFocused.bindTo(contextKeyService);
197197

198198
this.disposables.add(this.onDidChangeSelection(e => this._updateContextKey()));
199199
this.disposables.add(this.onDidChangeFocus(() => this._updateContextKey()));

src/vs/workbench/contrib/terminal/common/terminalContextKey.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export const enum TerminalContextKeyStrings {
3636
FindFocused = 'terminalFindFocused',
3737
TabsSingularSelection = 'terminalTabsSingularSelection',
3838
SplitTerminal = 'terminalSplitTerminal',
39+
SplitPaneActive = 'terminalSplitPaneActive',
3940
ShellType = 'terminalShellType',
4041
InTerminalRunCommandPicker = 'inTerminalRunCommandPicker',
4142
TerminalShellIntegrationEnabled = 'terminalShellIntegrationEnabled',
@@ -127,7 +128,10 @@ export namespace TerminalContextKeys {
127128
export const tabsSingularSelection = new RawContextKey<boolean>(TerminalContextKeyStrings.TabsSingularSelection, false, localize('terminalTabsSingularSelectedContextKey', "Whether one terminal is selected in the terminal tabs list."));
128129

129130
/** Whether the focused tab's terminal is a split terminal. */
130-
export const splitTerminal = new RawContextKey<boolean>(TerminalContextKeyStrings.SplitTerminal, false, localize('isSplitTerminalContextKey', "Whether the focused tab's terminal is a split terminal."));
131+
export const splitTerminalTabFocused = new RawContextKey<boolean>(TerminalContextKeyStrings.SplitTerminal, false, localize('isSplitTerminalContextKey', "Whether the focused tab's terminal is a split terminal."));
132+
133+
/** Whether the active terminal is a split pane */
134+
export const splitTerminalActive = new RawContextKey<boolean>(TerminalContextKeyStrings.SplitPaneActive, false, localize('splitPaneActive', "Whether the active terminal is a split pane."));
131135

132136
/** Whether the terminal run command picker is currently open. */
133137
export const inTerminalRunCommandPicker = new RawContextKey<boolean>(TerminalContextKeyStrings.InTerminalRunCommandPicker, false, localize('inTerminalRunCommandPickerContextKey', "Whether the terminal run command picker is currently open."));

src/vs/workbench/contrib/terminalContrib/sendSequence/browser/terminal.sendSequence.contribution.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,9 @@ registerSendSequenceKeybinding('\x1b[1;2H', { // Shift+home
158158
});
159159

160160
// Map alt+arrow to ctrl+arrow to allow word navigation in most shells to just work with alt. This
161-
// is non-standard behavior, but a lot of terminals act like this (see #190629). Note that
162-
// macOS uses different sequences here to get the desired behavior.
161+
// is non-standard behavior, but a lot of terminals act like this (see
162+
// https://github.com/microsoft/vscode/issues/190629). Note that macOS uses different sequences here
163+
// to get the desired behavior.
163164
registerSendSequenceKeybinding('\x1b[1;5A', {
164165
when: ContextKeyExpr.and(TerminalContextKeys.focus),
165166
primary: KeyMod.Alt | KeyCode.UpArrow

0 commit comments

Comments
 (0)