Goto declaration should store current cursor in navigation history (fixes #11727)
This commit is contained in:
parent
4e80960be5
commit
f02c44d371
|
@ -29,6 +29,7 @@ import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
|
|||
import {IStorageService} from 'vs/platform/storage/common/storage';
|
||||
import {IConfigurationService} from 'vs/platform/configuration/common/configuration';
|
||||
import {IEventService} from 'vs/platform/event/common/event';
|
||||
import {IHistoryService} from 'vs/workbench/services/history/common/history';
|
||||
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
|
||||
import {IMessageService, CancelAction} from 'vs/platform/message/common/message';
|
||||
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
|
||||
|
@ -56,6 +57,7 @@ export class TextFileEditor extends BaseTextEditor {
|
|||
@IInstantiationService instantiationService: IInstantiationService,
|
||||
@IWorkspaceContextService contextService: IWorkspaceContextService,
|
||||
@IStorageService storageService: IStorageService,
|
||||
@IHistoryService private historyService: IHistoryService,
|
||||
@IMessageService messageService: IMessageService,
|
||||
@IConfigurationService configurationService: IConfigurationService,
|
||||
@IEventService eventService: IEventService,
|
||||
|
@ -86,6 +88,14 @@ export class TextFileEditor extends BaseTextEditor {
|
|||
// Detect options
|
||||
const forceOpen = options && options.forceOpen;
|
||||
|
||||
// We have a current input in this editor and are about to either open a new editor or jump to a different
|
||||
// selection inside the editor. Thus we store the current selection into the navigation history so that
|
||||
// a user can navigate back to the exact position he left off.
|
||||
if (oldInput) {
|
||||
const selection = this.getControl().getSelection();
|
||||
this.historyService.add(oldInput, { selection: { startLineNumber: selection.startLineNumber, startColumn: selection.startColumn } });
|
||||
}
|
||||
|
||||
// Same Input
|
||||
if (!forceOpen && input.matches(oldInput)) {
|
||||
|
||||
|
|
|
@ -445,7 +445,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
|
|||
};
|
||||
}
|
||||
|
||||
this.addToStack(editor.input, options);
|
||||
this.add(editor.input, options);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -455,24 +455,31 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
|
|||
return; // do not push same editor input again
|
||||
}
|
||||
|
||||
this.addToStack(editor.input);
|
||||
this.add(editor.input);
|
||||
}
|
||||
|
||||
public add(input: IEditorInput, options?: ITextEditorOptions): void {
|
||||
if (!this.blockStackChanges) {
|
||||
this.addToStack(input, options);
|
||||
}
|
||||
}
|
||||
|
||||
private addToStack(input: IEditorInput, options?: ITextEditorOptions): void {
|
||||
|
||||
// Overwrite an entry in the stack if we have a matching input that comes
|
||||
// with editor options to indicate that this entry is more specific.
|
||||
// with editor options to indicate that this entry is more specific. Also
|
||||
// prevent entries that have the exact same options.
|
||||
let replace = false;
|
||||
if (this.stack[this.index]) {
|
||||
const currentEntry = this.stack[this.index];
|
||||
if (currentEntry.input.matches(input) && !currentEntry.options) {
|
||||
if (currentEntry.input.matches(input) && this.sameOptions(currentEntry.options, options)) {
|
||||
replace = true;
|
||||
}
|
||||
}
|
||||
|
||||
const entry = {
|
||||
input: input,
|
||||
options: options
|
||||
input,
|
||||
options
|
||||
};
|
||||
|
||||
// If we are not at the end of history, we remove anything after
|
||||
|
@ -506,6 +513,29 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
|
|||
});
|
||||
}
|
||||
|
||||
private sameOptions(optionsA?: ITextEditorOptions, optionsB?: ITextEditorOptions): boolean {
|
||||
if (!optionsA && !optionsB) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((!optionsA && optionsB) || (optionsA && !optionsB)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const s1 = optionsA.selection;
|
||||
const s2 = optionsB.selection;
|
||||
|
||||
if (!s1 && !s2) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((!s1 && s2) || (s1 && !s2)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return s1.startLineNumber === s2.startLineNumber; // we consider the history entry same if we are on the same line
|
||||
}
|
||||
|
||||
private restoreInStack(input: IEditorInput): void {
|
||||
let restoredInput: EditorInput;
|
||||
let restored = false;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
'use strict';
|
||||
|
||||
import {createDecorator, ServiceIdentifier} from 'vs/platform/instantiation/common/instantiation';
|
||||
import {IEditorInput} from 'vs/platform/editor/common/editor';
|
||||
import {IEditorInput, ITextEditorOptions} from 'vs/platform/editor/common/editor';
|
||||
|
||||
export const IHistoryService = createDecorator<IHistoryService>('historyService');
|
||||
|
||||
|
@ -23,6 +23,11 @@ export interface IHistoryService {
|
|||
*/
|
||||
popLastClosedEditor(): IRecentlyClosedEditor;
|
||||
|
||||
/**
|
||||
* Add an entry to the navigation stack of the history.
|
||||
*/
|
||||
add(input: IEditorInput, options?: ITextEditorOptions): void;
|
||||
|
||||
/**
|
||||
* Navigate forwards in history.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue