diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminal.contribution.ts b/src/vs/workbench/parts/terminal/electron-browser/terminal.contribution.ts index f5a81023233c4eb565014111d4c457eb41f68afa..6746c7c7688c7335cc8e9cf7e453b1d9bdd9160f 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminal.contribution.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminal.contribution.ts @@ -12,7 +12,7 @@ import {Extensions, IConfigurationRegistry} from 'vs/platform/configuration/comm import {ITerminalService, KEYBINDING_CONTEXT_TERMINAL_FOCUS, TERMINAL_PANEL_ID, TERMINAL_DEFAULT_SHELL_LINUX, TERMINAL_DEFAULT_SHELL_OSX, TERMINAL_DEFAULT_SHELL_WINDOWS} from 'vs/workbench/parts/terminal/electron-browser/terminal'; import {IWorkbenchActionRegistry, Extensions as ActionExtensions} from 'vs/workbench/common/actionRegistry'; import {KeyCode, KeyMod} from 'vs/base/common/keyCodes'; -import {KillTerminalAction, CopyTerminalSelectionAction, CreateNewTerminalAction, FocusTerminalAction, FocusNextTerminalAction, FocusPreviousTerminalAction, RunSelectedTextInTerminalAction, TerminalPasteAction, ToggleTerminalAction} from 'vs/workbench/parts/terminal/electron-browser/terminalActions'; +import {KillTerminalAction, CopyTerminalSelectionAction, CreateNewTerminalAction, FocusTerminalAction, FocusNextTerminalAction, FocusPreviousTerminalAction, RunSelectedTextInTerminalAction, ScrollDownTerminalAction, ScrollUpTerminalAction, TerminalPasteAction, ToggleTerminalAction} from 'vs/workbench/parts/terminal/electron-browser/terminalActions'; import {Registry} from 'vs/platform/platform'; import {SyncActionDescriptor} from 'vs/platform/actions/common/actions'; import {TerminalService} from 'vs/workbench/parts/terminal/electron-browser/terminalService'; @@ -123,3 +123,11 @@ actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ToggleTerminalAc primary: KeyMod.CtrlCmd | KeyCode.US_BACKTICK, mac: { primary: KeyMod.WinCtrl | KeyCode.US_BACKTICK } }), 'View: ' + ToggleTerminalAction.LABEL, nls.localize('viewCategory', "View")); +actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ScrollDownTerminalAction, ScrollDownTerminalAction.ID, ScrollDownTerminalAction.LABEL, { + primary: KeyMod.CtrlCmd | KeyCode.DownArrow, + linux: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.DownArrow } +}), ScrollDownTerminalAction.LABEL); +actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ScrollUpTerminalAction, ScrollUpTerminalAction.ID, ScrollUpTerminalAction.LABEL, { + primary: KeyMod.CtrlCmd | KeyCode.UpArrow, + linux: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.UpArrow } +}), ScrollUpTerminalAction.LABEL); diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminal.ts b/src/vs/workbench/parts/terminal/electron-browser/terminal.ts index 806ee3d63391634dd3e658f66a1d4d1fe95d0aeb..8f5a0c4d44a2e77ea56f53b9f1c22828f642f5af 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminal.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminal.ts @@ -71,6 +71,8 @@ export interface ITerminalService { hide(): TPromise; paste(): TPromise; runSelectedText(): TPromise; + scrollDown(): TPromise; + scrollUp(): TPromise; setActiveTerminal(index: number): TPromise; toggle(): TPromise; diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts b/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts index a8354dfb803ead561af8788054ffc69538929e6d..d7e11de7650c41098f763cd2e89ff14e7e553f8d 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts @@ -203,4 +203,38 @@ export class SwitchTerminalInstanceActionItem extends SelectActionItem { private updateItems(): void { this.setOptions(this.terminalService.getTerminalInstanceTitles(), this.terminalService.getActiveTerminalIndex()); } +} + +export class ScrollDownTerminalAction extends Action { + + public static ID = 'workbench.action.terminal.scrollDown'; + public static LABEL = nls.localize('workbench.action.terminal.scrollDown', "Terminal: Scroll Down"); + + constructor( + id: string, label: string, + @ITerminalService private terminalService: ITerminalService + ) { + super(id, label); + } + + public run(event?: any): TPromise { + return this.terminalService.scrollDown(); + } +} + +export class ScrollUpTerminalAction extends Action { + + public static ID = 'workbench.action.terminal.scrollUp'; + public static LABEL = nls.localize('workbench.action.terminal.scrollUp', "Terminal: Scroll Up"); + + constructor( + id: string, label: string, + @ITerminalService private terminalService: ITerminalService + ) { + super(id, label); + } + + public run(event?: any): TPromise { + return this.terminalService.scrollUp(); + } } \ No newline at end of file diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts b/src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts index 9cc48705c2502eba48447fa6df04757d4e7d7a64..484d4feef4d2bbf525e7db288e43893c07720f72 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts @@ -15,6 +15,7 @@ import {IKeybindingService, IKeybindingContextKey} from 'vs/platform/keybinding/ import {IMessageService, Severity} from 'vs/platform/message/common/message'; import {ITerminalFont} from 'vs/workbench/parts/terminal/electron-browser/terminalConfigHelper'; import {ITerminalProcess, ITerminalService} from 'vs/workbench/parts/terminal/electron-browser/terminal'; +import {ScrollDownTerminalAction, ScrollUpTerminalAction} from 'vs/workbench/parts/terminal/electron-browser/terminalActions'; import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace'; import {Keybinding} from 'vs/base/common/keyCodes'; import {StandardKeyboardEvent} from 'vs/base/browser/keyboardEvent'; @@ -32,7 +33,7 @@ export class TerminalInstance { private terminalDomElement: HTMLDivElement; private wrapperElement: HTMLDivElement; private font: ITerminalFont; - private toggleTabFocusModeKeybindings: Keybinding[]; + private skipTerminalKeybindings: Keybinding[]; public constructor( private terminalProcess: ITerminalProcess, @@ -48,7 +49,11 @@ export class TerminalInstance { ) { let self = this; this.toDispose = []; - this.toggleTabFocusModeKeybindings = self.keybindingService.lookupKeybindings(ToggleTabFocusModeAction.ID); + this.skipTerminalKeybindings = [].concat( + self.keybindingService.lookupKeybindings(ToggleTabFocusModeAction.ID), + self.keybindingService.lookupKeybindings(ScrollDownTerminalAction.ID), + self.keybindingService.lookupKeybindings(ScrollUpTerminalAction.ID)); + console.log(this.skipTerminalKeybindings); this.wrapperElement = document.createElement('div'); DOM.addClass(this.wrapperElement, 'terminal-wrapper'); this.terminalDomElement = document.createElement('div'); @@ -70,7 +75,7 @@ export class TerminalInstance { // Allow the toggle tab mode keybinding to pass through the terminal so that focus can // be escaped let standardKeyboardEvent = new StandardKeyboardEvent(event); - if (self.toggleTabFocusModeKeybindings.some((k) => standardKeyboardEvent.equals(k.value))) { + if (self.skipTerminalKeybindings.some((k) => standardKeyboardEvent.equals(k.value))) { event.preventDefault(); return false; } @@ -176,6 +181,14 @@ export class TerminalInstance { } } + public scrollDown(): void { + this.xterm.scrollDisp(1); + } + + public scrollUp(): void { + this.xterm.scrollDisp(-1); + } + public dispose(): void { if (this.wrapperElement) { this.parentDomElement.removeChild(this.wrapperElement); diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminalPanel.ts b/src/vs/workbench/parts/terminal/electron-browser/terminalPanel.ts index 5e90f0538073b6e7129b3758271dc52025ae99c7..54aa973823c666f34da46afb7b3b17d4dc1ade81 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminalPanel.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminalPanel.ts @@ -276,6 +276,14 @@ export class TerminalPanel extends Panel { this.themeStyleElement.innerHTML = css; } + public scrollDown(): void { + this.terminalInstances[this.terminalService.getActiveTerminalIndex()].scrollDown(); + } + + public scrollUp(): void { + this.terminalInstances[this.terminalService.getActiveTerminalIndex()].scrollUp(); + } + /** * Converts a CSS hex color (#rrggbb) to a CSS rgba color (rgba(r, g, b, a)). */ diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminalService.ts b/src/vs/workbench/parts/terminal/electron-browser/terminalService.ts index 1e08c032cd34ad82fb805223adf751f7bf6d3736..f52b6a01ac3cd423024f9c4793d27e5487c0795e 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminalService.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminalService.ts @@ -196,6 +196,18 @@ export class TerminalService implements ITerminalService { }); } + public scrollDown(): TPromise { + return this.showAndGetTerminalPanel().then((terminalPanel) => { + terminalPanel.scrollDown(); + }); + } + + public scrollUp(): TPromise { + return this.showAndGetTerminalPanel().then((terminalPanel) => { + terminalPanel.scrollUp(); + }); + } + private showAndGetTerminalPanel(): TPromise { return new TPromise((complete) => { let panel = this.panelService.getActivePanel();