Skip to content

Commit

Permalink
Polish command tracking, fix mac keybinding
Browse files Browse the repository at this point in the history
Part of #45435
  • Loading branch information
Tyriar committed Mar 26, 2018
1 parent bd3bcdc commit 437f5cf
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/vs/workbench/parts/terminal/common/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,8 @@ export interface ITerminalInstance {
}

export interface ITerminalCommandTracker {
focusPreviousCommand(): void;
focusNextCommand(): void;
scrollToPreviousCommand(): void;
scrollToNextCommand(): void;
selectToPreviousCommand(): void;
selectToNextCommand(): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { getTerminalDefaultShellUnixLike, getTerminalDefaultShellWindows } from
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions';
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { KillTerminalAction, CopyTerminalSelectionAction, CreateNewTerminalAction, CreateNewInActiveWorkspaceTerminalAction, FocusActiveTerminalAction, FocusNextTerminalAction, FocusPreviousTerminalAction, SelectDefaultShellWindowsTerminalAction, RunSelectedTextInTerminalAction, RunActiveFileInTerminalAction, ScrollDownTerminalAction, ScrollDownPageTerminalAction, ScrollToBottomTerminalAction, ScrollUpTerminalAction, ScrollUpPageTerminalAction, ScrollToTopTerminalAction, TerminalPasteAction, ToggleTerminalAction, ClearTerminalAction, AllowWorkspaceShellTerminalCommand, DisallowWorkspaceShellTerminalCommand, RenameTerminalAction, SelectAllTerminalAction, FocusTerminalFindWidgetAction, HideTerminalFindWidgetAction, ShowNextFindTermTerminalFindWidgetAction, ShowPreviousFindTermTerminalFindWidgetAction, DeleteWordLeftTerminalAction, DeleteWordRightTerminalAction, QuickOpenActionTermContributor, QuickOpenTermAction, TERMINAL_PICKER_PREFIX, MoveToLineStartTerminalAction, MoveToLineEndTerminalAction, SplitTerminalAction, FocusPreviousPaneTerminalAction, FocusNextPaneTerminalAction, ResizePaneLeftTerminalAction, ResizePaneRightTerminalAction, ResizePaneUpTerminalAction, ResizePaneDownTerminalAction, FocusPreviousCommandAction, FocusNextCommandAction, SelectToPreviousCommandAction, SelectToNextCommandAction } from 'vs/workbench/parts/terminal/electron-browser/terminalActions';
import { KillTerminalAction, CopyTerminalSelectionAction, CreateNewTerminalAction, CreateNewInActiveWorkspaceTerminalAction, FocusActiveTerminalAction, FocusNextTerminalAction, FocusPreviousTerminalAction, SelectDefaultShellWindowsTerminalAction, RunSelectedTextInTerminalAction, RunActiveFileInTerminalAction, ScrollDownTerminalAction, ScrollDownPageTerminalAction, ScrollToBottomTerminalAction, ScrollUpTerminalAction, ScrollUpPageTerminalAction, ScrollToTopTerminalAction, TerminalPasteAction, ToggleTerminalAction, ClearTerminalAction, AllowWorkspaceShellTerminalCommand, DisallowWorkspaceShellTerminalCommand, RenameTerminalAction, SelectAllTerminalAction, FocusTerminalFindWidgetAction, HideTerminalFindWidgetAction, ShowNextFindTermTerminalFindWidgetAction, ShowPreviousFindTermTerminalFindWidgetAction, DeleteWordLeftTerminalAction, DeleteWordRightTerminalAction, QuickOpenActionTermContributor, QuickOpenTermAction, TERMINAL_PICKER_PREFIX, MoveToLineStartTerminalAction, MoveToLineEndTerminalAction, SplitTerminalAction, FocusPreviousPaneTerminalAction, FocusNextPaneTerminalAction, ResizePaneLeftTerminalAction, ResizePaneRightTerminalAction, ResizePaneUpTerminalAction, ResizePaneDownTerminalAction, ScrollToPreviousCommandAction, ScrollToNextCommandAction, SelectToPreviousCommandAction, SelectToNextCommandAction } from 'vs/workbench/parts/terminal/electron-browser/terminalActions';
import { Registry } from 'vs/platform/registry/common/platform';
import { ShowAllCommandsAction } from 'vs/workbench/parts/quickopen/browser/commandsHandler';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
Expand Down Expand Up @@ -280,8 +280,8 @@ configurationRegistry.registerConfiguration({
ResizePaneRightTerminalAction.ID,
ResizePaneUpTerminalAction.ID,
ResizePaneDownTerminalAction.ID,
FocusPreviousCommandAction.ID,
FocusNextCommandAction.ID,
ScrollToPreviousCommandAction.ID,
ScrollToNextCommandAction.ID,
SelectToPreviousCommandAction.ID,
SelectToNextCommandAction.ID
].sort()
Expand Down Expand Up @@ -372,7 +372,7 @@ actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ToggleTerminalAc
mac: { primary: KeyMod.WinCtrl | KeyCode.US_BACKTICK }
}), 'View: Toggle Integrated Terminal', nls.localize('viewCategory', "View"));
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ScrollDownTerminalAction, ScrollDownTerminalAction.ID, ScrollDownTerminalAction.LABEL, {
primary: KeyMod.CtrlCmd | KeyCode.DownArrow,
primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.PageDown,
linux: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.DownArrow }
}, KEYBINDING_CONTEXT_TERMINAL_FOCUS), 'Terminal: Scroll Down (Line)', category);
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ScrollDownPageTerminalAction, ScrollDownPageTerminalAction.ID, ScrollDownPageTerminalAction.LABEL, {
Expand All @@ -384,7 +384,7 @@ actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ScrollToBottomTe
linux: { primary: KeyMod.Shift | KeyCode.End }
}, KEYBINDING_CONTEXT_TERMINAL_FOCUS), 'Terminal: Scroll to Bottom', category);
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ScrollUpTerminalAction, ScrollUpTerminalAction.ID, ScrollUpTerminalAction.LABEL, {
primary: KeyMod.CtrlCmd | KeyCode.UpArrow,
primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.PageUp,
linux: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.UpArrow },
}, KEYBINDING_CONTEXT_TERMINAL_FOCUS), 'Terminal: Scroll Up (Line)', category);
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ScrollUpPageTerminalAction, ScrollUpPageTerminalAction.ID, ScrollUpPageTerminalAction.LABEL, {
Expand Down Expand Up @@ -478,14 +478,14 @@ actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ResizePaneDownTe
linux: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.DownArrow },
mac: { primary: KeyMod.CtrlCmd | KeyMod.WinCtrl | KeyCode.DownArrow }
}, KEYBINDING_CONTEXT_TERMINAL_FOCUS), 'Terminal: Resize Pane Down', category);
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(FocusPreviousCommandAction, FocusPreviousCommandAction.ID, FocusPreviousCommandAction.LABEL, {
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ScrollToPreviousCommandAction, ScrollToPreviousCommandAction.ID, ScrollToPreviousCommandAction.LABEL, {
primary: null,
mac: { primary: KeyMod.CtrlCmd | KeyCode.UpArrow }
}, KEYBINDING_CONTEXT_TERMINAL_FOCUS), 'Terminal: Focus Previous Command', category);
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(FocusNextCommandAction, FocusNextCommandAction.ID, FocusNextCommandAction.LABEL, {
}, KEYBINDING_CONTEXT_TERMINAL_FOCUS), 'Terminal: Scroll To Previous Command', category);
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ScrollToNextCommandAction, ScrollToNextCommandAction.ID, ScrollToNextCommandAction.LABEL, {
primary: null,
mac: { primary: KeyMod.CtrlCmd | KeyCode.DownArrow }
}, KEYBINDING_CONTEXT_TERMINAL_FOCUS), 'Terminal: Focus Next Command', category);
}, KEYBINDING_CONTEXT_TERMINAL_FOCUS), 'Terminal: Scroll To Next Command', category);
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(SelectToPreviousCommandAction, SelectToPreviousCommandAction.ID, SelectToPreviousCommandAction.LABEL, {
primary: null,
mac: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.UpArrow }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -982,9 +982,9 @@ export class RenameTerminalQuickOpenAction extends RenameTerminalAction {
}
}

export class FocusPreviousCommandAction extends Action {
public static readonly ID = 'workbench.action.terminal.focusPreviousCommand';
public static readonly LABEL = nls.localize('workbench.action.terminal.focusPreviousCommand', "Focus Previous Command");
export class ScrollToPreviousCommandAction extends Action {
public static readonly ID = 'workbench.action.terminal.scrollToPreviousCommand';
public static readonly LABEL = nls.localize('workbench.action.terminal.scrollToPreviousCommand', "Scroll To Previous Command");

constructor(
id: string, label: string,
Expand All @@ -996,15 +996,15 @@ export class FocusPreviousCommandAction extends Action {
public run(): TPromise<any> {
const instance = this.terminalService.getActiveInstance();
if (instance) {
instance.commandTracker.focusPreviousCommand();
instance.commandTracker.scrollToPreviousCommand();
}
return TPromise.as(void 0);
}
}

export class FocusNextCommandAction extends Action {
public static readonly ID = 'workbench.action.terminal.focusNextCommand';
public static readonly LABEL = nls.localize('workbench.action.terminal.focusNextCommand', "Focus Next Command");
export class ScrollToNextCommandAction extends Action {
public static readonly ID = 'workbench.action.terminal.scrollToNextCommand';
public static readonly LABEL = nls.localize('workbench.action.terminal.scrollToNextCommand', "Scroll To Next Command");

constructor(
id: string, label: string,
Expand All @@ -1016,7 +1016,7 @@ export class FocusNextCommandAction extends Action {
public run(): TPromise<any> {
const instance = this.terminalService.getActiveInstance();
if (instance) {
instance.commandTracker.focusNextCommand();
instance.commandTracker.scrollToNextCommand();
}
return TPromise.as(void 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class TerminalCommandTracker implements ITerminalCommandTracker {
}
}

public focusPreviousCommand(retainSelection: boolean = false): void {
public scrollToPreviousCommand(retainSelection: boolean = false): void {
if (!retainSelection) {
this._selectionStart = null;
}
Expand All @@ -67,7 +67,7 @@ export class TerminalCommandTracker implements ITerminalCommandTracker {
this._xterm.scrollToLine(this._currentMarker.line);
}

public focusNextCommand(retainSelection: boolean = false): void {
public scrollToNextCommand(retainSelection: boolean = false): void {
if (!retainSelection) {
this._selectionStart = null;
}
Expand Down Expand Up @@ -95,16 +95,15 @@ export class TerminalCommandTracker implements ITerminalCommandTracker {
if (this._selectionStart === null) {
this._selectionStart = this._currentMarker;
}
this.focusPreviousCommand(true);
this.scrollToPreviousCommand(true);
this._selectLines(this._currentMarker, this._selectionStart);
}

public selectToNextCommand(): void {
if (this._selectionStart === null) {
this._selectionStart = this._currentMarker;
}
this.focusNextCommand(true);
// if (!this._currentMarker
this.scrollToNextCommand(true);
this._selectLines(this._currentMarker, this._selectionStart);
}

Expand Down

0 comments on commit 437f5cf

Please sign in to comment.