提交 41cd56af 编写于 作者: B Brandon Bloom 提交者: Benjamin Pasero

Implements #33902 - "Go Last" (#33715)

上级 f04f9320
......@@ -30,7 +30,7 @@ import { KeyMod, KeyChord, KeyCode } from 'vs/base/common/keyCodes';
import {
CloseEditorsInGroupAction, CloseEditorsInOtherGroupsAction, CloseAllEditorsAction, MoveGroupLeftAction, MoveGroupRightAction, SplitEditorAction, JoinTwoGroupsAction, KeepEditorAction, CloseOtherEditorsInGroupAction, OpenToSideAction, RevertAndCloseEditorAction,
NavigateBetweenGroupsAction, FocusActiveGroupAction, FocusFirstGroupAction, FocusSecondGroupAction, FocusThirdGroupAction, EvenGroupWidthsAction, MaximizeGroupAction, MinimizeOtherGroupsAction, FocusPreviousGroup, FocusNextGroup, ShowEditorsInGroupOneAction,
toEditorQuickOpenEntry, CloseLeftEditorsInGroupAction, CloseRightEditorsInGroupAction, CloseUnmodifiedEditorsInGroupAction, OpenNextEditor, OpenPreviousEditor, NavigateBackwardsAction, NavigateForwardAction, ReopenClosedEditorAction, OpenPreviousRecentlyUsedEditorInGroupAction, NAVIGATE_IN_GROUP_ONE_PREFIX,
toEditorQuickOpenEntry, CloseLeftEditorsInGroupAction, CloseRightEditorsInGroupAction, CloseUnmodifiedEditorsInGroupAction, OpenNextEditor, OpenPreviousEditor, NavigateBackwardsAction, NavigateForwardAction, NavigateLastAction, ReopenClosedEditorAction, OpenPreviousRecentlyUsedEditorInGroupAction, NAVIGATE_IN_GROUP_ONE_PREFIX,
OpenPreviousEditorFromHistoryAction, ShowAllEditorsAction, NAVIGATE_ALL_EDITORS_GROUP_PREFIX, ClearEditorHistoryAction, ShowEditorsInGroupTwoAction, MoveEditorRightInGroupAction, OpenNextEditorInGroup, OpenPreviousEditorInGroup, OpenNextRecentlyUsedEditorAction, OpenPreviousRecentlyUsedEditorAction,
NAVIGATE_IN_GROUP_TWO_PREFIX, ShowEditorsInGroupThreeAction, NAVIGATE_IN_GROUP_THREE_PREFIX, FocusLastEditorInStackAction, OpenNextRecentlyUsedEditorInGroupAction, MoveEditorToPreviousGroupAction, MoveEditorToNextGroupAction, MoveEditorLeftInGroupAction, ClearRecentFilesAction
} from 'vs/workbench/browser/parts/editor/editorActions';
......@@ -368,6 +368,7 @@ registry.registerWorkbenchAction(new SyncActionDescriptor(FocusPreviousGroup, Fo
registry.registerWorkbenchAction(new SyncActionDescriptor(FocusNextGroup, FocusNextGroup.ID, FocusNextGroup.LABEL, { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.RightArrow) }), 'View: Focus Next Group', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(NavigateForwardAction, NavigateForwardAction.ID, NavigateForwardAction.LABEL, { primary: null, win: { primary: KeyMod.Alt | KeyCode.RightArrow }, mac: { primary: KeyMod.WinCtrl | KeyMod.Shift | KeyCode.US_MINUS }, linux: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.US_MINUS } }), 'Go Forward');
registry.registerWorkbenchAction(new SyncActionDescriptor(NavigateBackwardsAction, NavigateBackwardsAction.ID, NavigateBackwardsAction.LABEL, { primary: null, win: { primary: KeyMod.Alt | KeyCode.LeftArrow }, mac: { primary: KeyMod.WinCtrl | KeyCode.US_MINUS }, linux: { primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.US_MINUS } }), 'Go Back');
registry.registerWorkbenchAction(new SyncActionDescriptor(NavigateLastAction, NavigateLastAction.ID, NavigateLastAction.LABEL), 'Go Last');
registry.registerWorkbenchAction(new SyncActionDescriptor(OpenPreviousEditorFromHistoryAction, OpenPreviousEditorFromHistoryAction.ID, OpenPreviousEditorFromHistoryAction.LABEL), 'Open Previous Editor from History');
registry.registerWorkbenchAction(new SyncActionDescriptor(ClearEditorHistoryAction, ClearEditorHistoryAction.ID, ClearEditorHistoryAction.LABEL), 'Clear Editor History');
registry.registerWorkbenchAction(new SyncActionDescriptor(RevertAndCloseEditorAction, RevertAndCloseEditorAction.ID, RevertAndCloseEditorAction.LABEL), 'View: Revert and Close Editor', category);
......
......@@ -1116,6 +1116,22 @@ export class NavigateBackwardsAction extends Action {
}
}
export class NavigateLastAction extends Action {
public static ID = 'workbench.action.navigateLast';
public static LABEL = nls.localize('navigateLast', "Go Last");
constructor(id: string, label: string, @IHistoryService private historyService: IHistoryService) {
super(id, label);
}
public run(): TPromise<any> {
this.historyService.last();
return TPromise.as(null);
}
}
export class ReopenClosedEditorAction extends Action {
public static ID = 'workbench.action.reopenClosedEditor';
......
......@@ -149,6 +149,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
private stack: IStackEntry[];
private index: number;
private lastIndex: number;
private navigatingInStack: boolean;
private currentFileEditorState: EditorState;
......@@ -172,6 +173,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
super(editorGroupService, editorService);
this.index = -1;
this.lastIndex = -1;
this.stack = [];
this.recentlyClosedFiles = [];
this.loaded = false;
......@@ -181,6 +183,11 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
this.registerListeners();
}
private setIndex(value: number): void {
this.lastIndex = this.index;
this.index = value;
}
private getExcludes(root?: URI): IExpression {
const scope = root ? { resource: root } : void 0;
......@@ -246,7 +253,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
}
private doForwardInEditors(): void {
this.index++;
this.setIndex(this.index + 1);
this.navigate();
}
......@@ -260,7 +267,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
const previousEntry = this.stack[currentIndex];
if (!this.matches(currentEntry.input, previousEntry.input)) {
this.index = currentIndex;
this.setIndex(currentIndex);
this.navigate(true /* across editors */);
break;
}
......@@ -277,8 +284,17 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
}
}
public last(): void {
if (this.lastIndex === -1) {
this.back();
} else {
this.setIndex(this.lastIndex);
this.navigate();
}
}
private doBackInEditors(): void {
this.index--;
this.setIndex(this.index - 1);
this.navigate();
}
......@@ -292,7 +308,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
const previousEntry = this.stack[currentIndex];
if (!this.matches(currentEntry.input, previousEntry.input)) {
this.index = currentIndex;
this.setIndex(currentIndex);
this.navigate(true /* across editors */);
break;
}
......@@ -303,6 +319,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
this.ensureHistoryLoaded();
this.index = -1;
this.lastIndex = -1;
this.stack.splice(0);
this.history = [];
this.recentlyClosedFiles = [];
......@@ -505,14 +522,14 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
// Add to stack at current position
else {
this.index++;
this.setIndex(this.index + 1);
this.stack.splice(this.index, 0, entry);
// Check for limit
if (this.stack.length > HistoryService.MAX_STACK_ITEMS) {
this.stack.shift(); // remove first and dispose
if (this.index > 0) {
this.index--;
this.setIndex(this.index - 1);
}
}
}
......@@ -562,6 +579,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
private removeFromStack(arg1: IEditorInput | IResourceInput | FileChangesEvent): void {
this.stack = this.stack.filter(e => !this.matches(arg1, e.input));
this.index = this.stack.length - 1; // reset index
this.lastIndex = -1;
}
private removeFromRecentlyClosedFiles(arg1: IEditorInput | IResourceInput | FileChangesEvent): void {
......
......@@ -40,6 +40,11 @@ export interface IHistoryService {
*/
back(acrossEditors?: boolean): void;
/**
* Navigate forward or backwards to previous entry in history.
*/
last(): void;
/**
* Removes an entry from history.
*/
......
......@@ -262,6 +262,9 @@ export class TestHistoryService implements IHistoryService {
public back(acrossEditors?: boolean): void {
}
public last(): void {
}
public remove(input: IEditorInput | IResourceInput): void {
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册