提交 7c734490 编写于 作者: D Daniel Imms

Support standard terminal scroll down/up 1 line keybindings

Windows: ctrl+up/down
Linux: ctrl+shift+up/down
Mac: cmd+up/down

Fixes #10302
上级 661bf0db
......@@ -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);
......@@ -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>;
......
......@@ -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();
}
}
\ No newline at end of file
......@@ -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);
......
......@@ -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)).
*/
......
......@@ -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();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册