Skip to content

Commit 860005c

Browse files
committed
Add sticky scroll tooltip and command nav actions to panel
Fixes #198013
1 parent 0d552b5 commit 860005c

4 files changed

Lines changed: 49 additions & 27 deletions

File tree

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { PICK_WORKSPACE_FOLDER_COMMAND_ID } from 'vs/workbench/browser/actions/w
3333
import { CLOSE_EDITOR_COMMAND_ID } from 'vs/workbench/browser/parts/editor/editorCommands';
3434
import { Direction, ICreateTerminalOptions, IDetachedTerminalInstance, ITerminalConfigHelper, ITerminalEditorService, ITerminalGroupService, ITerminalInstance, ITerminalInstanceService, ITerminalService, IXtermTerminal } from 'vs/workbench/contrib/terminal/browser/terminal';
3535
import { TerminalQuickAccessProvider } from 'vs/workbench/contrib/terminal/browser/terminalQuickAccess';
36-
import { IRemoteTerminalAttachTarget, ITerminalProfileResolverService, ITerminalProfileService, TerminalCommandId } from 'vs/workbench/contrib/terminal/common/terminal';
36+
import { IRemoteTerminalAttachTarget, ITerminalProfileResolverService, ITerminalProfileService, TERMINAL_VIEW_ID, TerminalCommandId } from 'vs/workbench/contrib/terminal/common/terminal';
3737
import { TerminalContextKeys } from 'vs/workbench/contrib/terminal/common/terminalContextKey';
3838
import { createProfileSchemaEnums } from 'vs/platform/terminal/common/terminalProfiles';
3939
import { terminalStrings } from 'vs/workbench/contrib/terminal/common/terminalStrings';
@@ -928,25 +928,45 @@ export function registerTerminalActions() {
928928

929929
registerActiveInstanceAction({
930930
id: TerminalCommandId.ScrollToPreviousCommand,
931-
title: { value: localize('workbench.action.terminal.scrollToPreviousCommand', "Scroll To Previous Command"), original: 'Scroll To Previous Command' },
931+
title: terminalStrings.scrollToPreviousCommand,
932932
keybinding: {
933933
primary: KeyMod.CtrlCmd | KeyCode.UpArrow,
934934
when: ContextKeyExpr.and(TerminalContextKeys.focus, CONTEXT_ACCESSIBILITY_MODE_ENABLED.negate()),
935935
weight: KeybindingWeight.WorkbenchContrib
936936
},
937937
precondition: ContextKeyExpr.or(TerminalContextKeys.processSupported, TerminalContextKeys.terminalHasBeenCreated),
938+
icon: Codicon.arrowUp,
939+
menu: [
940+
{
941+
id: MenuId.ViewTitle,
942+
group: 'navigation',
943+
order: 4,
944+
when: ContextKeyExpr.equals('view', TERMINAL_VIEW_ID),
945+
isHiddenByDefault: true
946+
}
947+
],
938948
run: (activeInstance) => activeInstance.xterm?.markTracker.scrollToPreviousMark(undefined, undefined, activeInstance.capabilities.has(TerminalCapability.CommandDetection))
939949
});
940950

941951
registerActiveInstanceAction({
942952
id: TerminalCommandId.ScrollToNextCommand,
943-
title: { value: localize('workbench.action.terminal.scrollToNextCommand', "Scroll To Next Command"), original: 'Scroll To Next Command' },
953+
title: terminalStrings.scrollToNextCommand,
944954
keybinding: {
945955
primary: KeyMod.CtrlCmd | KeyCode.DownArrow,
946956
when: ContextKeyExpr.and(TerminalContextKeys.focus, CONTEXT_ACCESSIBILITY_MODE_ENABLED.negate()),
947957
weight: KeybindingWeight.WorkbenchContrib
948958
},
949959
precondition: ContextKeyExpr.or(TerminalContextKeys.processSupported, TerminalContextKeys.terminalHasBeenCreated),
960+
icon: Codicon.arrowDown,
961+
menu: [
962+
{
963+
id: MenuId.ViewTitle,
964+
group: 'navigation',
965+
order: 4,
966+
when: ContextKeyExpr.equals('view', TERMINAL_VIEW_ID),
967+
isHiddenByDefault: true
968+
}
969+
],
950970
run: (activeInstance) => {
951971
activeInstance.xterm?.markTracker.scrollToNextMark();
952972
activeInstance.focus();

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ export function setupTerminalMenus(): void {
515515
title: localize('workbench.action.terminal.clearLong', "Clear Terminal"),
516516
icon: Codicon.clearAll
517517
},
518-
group: 'navigation',
518+
group: 'execute',
519519
order: 4,
520520
when: ContextKeyExpr.equals('view', TERMINAL_VIEW_ID),
521521
isHiddenByDefault: true
@@ -529,7 +529,7 @@ export function setupTerminalMenus(): void {
529529
title: localize('workbench.action.terminal.runActiveFile', "Run Active File"),
530530
icon: Codicon.run
531531
},
532-
group: 'navigation',
532+
group: 'execute',
533533
order: 5,
534534
when: ContextKeyExpr.equals('view', TERMINAL_VIEW_ID),
535535
isHiddenByDefault: true
@@ -543,7 +543,7 @@ export function setupTerminalMenus(): void {
543543
title: localize('workbench.action.terminal.runSelectedText', "Run Selected Text"),
544544
icon: Codicon.selection
545545
},
546-
group: 'navigation',
546+
group: 'execute',
547547
order: 6,
548548
when: ContextKeyExpr.equals('view', TERMINAL_VIEW_ID),
549549
isHiddenByDefault: true

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,13 @@ export const terminalStrings = {
8585
stickyScroll: {
8686
value: localize('stickyScroll', "Sticky Scroll"),
8787
original: 'Sticky Scroll'
88+
},
89+
scrollToPreviousCommand: {
90+
value: localize('workbench.action.terminal.scrollToPreviousCommand', "Scroll To Previous Command"),
91+
original: 'Scroll To Previous Command'
92+
},
93+
scrollToNextCommand: {
94+
value: localize('workbench.action.terminal.scrollToNextCommand', "Scroll To Next Command"),
95+
original: 'Scroll To Next Command'
8896
}
8997
};

src/vs/workbench/contrib/terminalContrib/stickyScroll/browser/terminalStickyScrollOverlay.ts

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ import type { SerializeAddon as SerializeAddonType } from '@xterm/addon-serializ
77
import type { IBufferLine, IMarker, ITerminalOptions, ITheme, Terminal as RawXtermTerminal, Terminal as XTermTerminal } from '@xterm/xterm';
88
import { importAMDNodeModule } from 'vs/amdX';
99
import { $, addDisposableListener, addStandardDisposableListener, getWindow } from 'vs/base/browser/dom';
10-
import { KeybindingLabel } from 'vs/base/browser/ui/keybindingLabel/keybindingLabel';
1110
import { CancelablePromise, createCancelablePromise } from 'vs/base/common/async';
1211
import { debounce, memoize, throttle } from 'vs/base/common/decorators';
1312
import { Event } from 'vs/base/common/event';
1413
import { Disposable, MutableDisposable, combinedDisposable, toDisposable } from 'vs/base/common/lifecycle';
15-
import { OS } from 'vs/base/common/platform';
1614
import 'vs/css!./media/stickyScroll';
1715
import { localize } from 'vs/nls';
1816
import { IMenu, IMenuService, MenuId } from 'vs/platform/actions/common/actions';
@@ -27,7 +25,8 @@ import { IThemeService } from 'vs/platform/theme/common/themeService';
2725
import { ITerminalInstance, IXtermColorProvider, IXtermTerminal } from 'vs/workbench/contrib/terminal/browser/terminal';
2826
import { openContextMenu } from 'vs/workbench/contrib/terminal/browser/terminalContextMenu';
2927
import { IXtermCore } from 'vs/workbench/contrib/terminal/browser/xterm-private';
30-
import { TERMINAL_CONFIG_SECTION } from 'vs/workbench/contrib/terminal/common/terminal';
28+
import { TERMINAL_CONFIG_SECTION, TerminalCommandId } from 'vs/workbench/contrib/terminal/common/terminal';
29+
import { terminalStrings } from 'vs/workbench/contrib/terminal/common/terminalStrings';
3130
import { terminalStickyScrollHoverBackground } from 'vs/workbench/contrib/terminalContrib/stickyScroll/browser/terminalStickyScrollColorRegistry';
3231

3332
const enum OverlayState {
@@ -327,28 +326,23 @@ export class TerminalStickyScrollOverlay extends Disposable {
327326
this._xterm.raw.element.parentElement.append(this._element);
328327
this._register(toDisposable(() => this._element?.remove()));
329328

330-
// Create command navigation keybinding hint if appropriate
331-
const scrollToPreviousCommandKeybinding = this._keybindingService.lookupKeybinding('workbench.action.terminal.scrollToPreviousCommand');
329+
// Fill tooltip
330+
let hoverTitle = localize('stickyScrollHoverTitle', 'Navigate to Command');
331+
const scrollToPreviousCommandKeybinding = this._keybindingService.lookupKeybinding(TerminalCommandId.ScrollToPreviousCommand);
332332
if (scrollToPreviousCommandKeybinding) {
333-
const keybindingHint = $('.keybinding-hint');
334-
const localizedText = localize({
335-
key: 'command-navigation-hint',
336-
comment: ['{0} is the localized keybinding to navigate commands']
337-
}, '{0} to navigate commands', '{0}');
338-
const localizedTextPrefix = localizedText.substring(0, localizedText.indexOf('{0}'));
339-
const localizedTextSuffix = localizedText.substring(localizedText.indexOf('{0}') + 3);
340-
const label = new KeybindingLabel(keybindingHint, OS);
341-
label.set(scrollToPreviousCommandKeybinding);
342-
// Insert and use a non-breaking space for boundaries to space out naturally
343-
if (localizedTextPrefix) {
344-
label.element.insertAdjacentText('beforebegin', localizedTextPrefix.replace(/ $/, '\u00A0'));
333+
const label = scrollToPreviousCommandKeybinding.getLabel();
334+
if (label) {
335+
hoverTitle += '\n' + localize('labelWithKeybinding', "{0} ({1})", terminalStrings.scrollToPreviousCommand.value, label);
345336
}
346-
if (localizedTextSuffix) {
347-
label.element.insertAdjacentText('afterend', localizedTextSuffix.replace(/^ /, '\u00A0'));
337+
}
338+
const scrollToNextCommandKeybinding = this._keybindingService.lookupKeybinding(TerminalCommandId.ScrollToNextCommand);
339+
if (scrollToNextCommandKeybinding) {
340+
const label = scrollToNextCommandKeybinding.getLabel();
341+
if (label) {
342+
hoverTitle += '\n' + localize('labelWithKeybinding', "{0} ({1})", terminalStrings.scrollToNextCommand.value, label);
348343
}
349-
350-
hoverOverlay.append(keybindingHint);
351344
}
345+
hoverOverlay.title = hoverTitle;
352346

353347
const scrollBarWidth = (this._xterm.raw as any as { _core: IXtermCore })._core.viewport?.scrollBarWidth;
354348
if (scrollBarWidth !== undefined) {

0 commit comments

Comments
 (0)