Skip to content

Commit

Permalink
Support standard terminal scroll down/up 1 line keybindings
Browse files Browse the repository at this point in the history
Windows: ctrl+up/down
Linux: ctrl+shift+up/down
Mac: cmd+up/down

Fixes #10302
  • Loading branch information
Tyriar committed Aug 8, 2016
1 parent 661bf0d commit 7c73449
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
2 changes: 2 additions & 0 deletions src/vs/workbench/parts/terminal/electron-browser/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ export interface ITerminalService {
hide(): TPromise<any>;
paste(): TPromise<any>;
runSelectedText(): TPromise<any>;
scrollDown(): TPromise<any>;
scrollUp(): TPromise<any>;
setActiveTerminal(index: number): TPromise<any>;
toggle(): TPromise<any>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> {
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<any> {
return this.terminalService.scrollUp();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand All @@ -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');
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)).
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,18 @@ export class TerminalService implements ITerminalService {
});
}

public scrollDown(): TPromise<any> {
return this.showAndGetTerminalPanel().then((terminalPanel) => {
terminalPanel.scrollDown();
});
}

public scrollUp(): TPromise<any> {
return this.showAndGetTerminalPanel().then((terminalPanel) => {
terminalPanel.scrollUp();
});
}

private showAndGetTerminalPanel(): TPromise<TerminalPanel> {
return new TPromise<TerminalPanel>((complete) => {
let panel = this.panelService.getActivePanel();
Expand Down

0 comments on commit 7c73449

Please sign in to comment.