mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 13:46:13 +00:00
history - stop using heavy typed editor inputs for reopening closed editors (#126728)
This commit is contained in:
parent
a17d538206
commit
e490174a3a
|
@ -7,7 +7,7 @@ import { localize } from 'vs/nls';
|
||||||
import { URI, UriComponents } from 'vs/base/common/uri';
|
import { URI, UriComponents } from 'vs/base/common/uri';
|
||||||
import { IEditor } from 'vs/editor/common/editorCommon';
|
import { IEditor } from 'vs/editor/common/editorCommon';
|
||||||
import { ITextEditorOptions, IResourceEditorInput, TextEditorSelectionRevealType, IEditorOptions } from 'vs/platform/editor/common/editor';
|
import { ITextEditorOptions, IResourceEditorInput, TextEditorSelectionRevealType, IEditorOptions } from 'vs/platform/editor/common/editor';
|
||||||
import { IEditorInput, IEditorPane, EditorExtensions, IEditorCloseEvent, IEditorInputFactoryRegistry, EditorResourceAccessor, IEditorIdentifier, GroupIdentifier, EditorsOrder, SideBySideEditor } from 'vs/workbench/common/editor';
|
import { IEditorInput, IEditorPane, EditorExtensions, IEditorCloseEvent, IEditorInputFactoryRegistry, EditorResourceAccessor, IEditorIdentifier, GroupIdentifier, EditorsOrder, SideBySideEditor, IUntypedEditorInput } from 'vs/workbench/common/editor';
|
||||||
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
|
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
|
||||||
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||||
import { IHistoryService } from 'vs/workbench/services/history/common/history';
|
import { IHistoryService } from 'vs/workbench/services/history/common/history';
|
||||||
|
@ -94,7 +94,7 @@ interface IStackEntry {
|
||||||
interface IRecentlyClosedEditor {
|
interface IRecentlyClosedEditor {
|
||||||
resource: URI | undefined;
|
resource: URI | undefined;
|
||||||
associatedResources: URI[];
|
associatedResources: URI[];
|
||||||
serialized: { typeId: string, value: string };
|
editor: IUntypedEditorInput;
|
||||||
index: number;
|
index: number;
|
||||||
sticky: boolean;
|
sticky: boolean;
|
||||||
}
|
}
|
||||||
|
@ -698,14 +698,9 @@ export class HistoryService extends Disposable implements IHistoryService {
|
||||||
return; // ignore if editor was replaced
|
return; // ignore if editor was replaced
|
||||||
}
|
}
|
||||||
|
|
||||||
const editorSerializer = this.editorInputFactory.getEditorInputSerializer(editor);
|
const untypedEditor = editor.asResourceEditorInput(event.groupId);
|
||||||
if (!editorSerializer || !editorSerializer.canSerialize(editor)) {
|
if (!untypedEditor) {
|
||||||
return; // we need a serializer from this point that can serialize this editor
|
return; // we need a untyped editor to restore from going forward
|
||||||
}
|
|
||||||
|
|
||||||
const serialized = editorSerializer.serialize(editor);
|
|
||||||
if (typeof serialized !== 'string') {
|
|
||||||
return; // we need something to deserialize from
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const associatedResources: URI[] = [];
|
const associatedResources: URI[] = [];
|
||||||
|
@ -723,7 +718,7 @@ export class HistoryService extends Disposable implements IHistoryService {
|
||||||
this.recentlyClosedEditors.push({
|
this.recentlyClosedEditors.push({
|
||||||
resource: EditorResourceAccessor.getOriginalUri(editor),
|
resource: EditorResourceAccessor.getOriginalUri(editor),
|
||||||
associatedResources,
|
associatedResources,
|
||||||
serialized: { typeId: editor.typeId, value: serialized },
|
editor: untypedEditor,
|
||||||
index: event.index,
|
index: event.index,
|
||||||
sticky: event.sticky
|
sticky: event.sticky
|
||||||
});
|
});
|
||||||
|
@ -767,10 +762,9 @@ export class HistoryService extends Disposable implements IHistoryService {
|
||||||
options = { pinned: true, index: lastClosedEditor.index, ignoreError: true };
|
options = { pinned: true, index: lastClosedEditor.index, ignoreError: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deserialize and open editor unless already opened
|
// Re-open editor unless already opened
|
||||||
const restoredEditor = this.editorInputFactory.getEditorInputSerializer(lastClosedEditor.serialized.typeId)?.deserialize(this.instantiationService, lastClosedEditor.serialized.value);
|
|
||||||
let editorPane: IEditorPane | undefined = undefined;
|
let editorPane: IEditorPane | undefined = undefined;
|
||||||
if (restoredEditor && !this.editorGroupService.activeGroup.contains(restoredEditor)) {
|
if (!this.editorGroupService.activeGroup.contains(lastClosedEditor.editor)) {
|
||||||
// Fix for https://github.com/microsoft/vscode/issues/107850
|
// Fix for https://github.com/microsoft/vscode/issues/107850
|
||||||
// If opening an editor fails, it is possible that we get
|
// If opening an editor fails, it is possible that we get
|
||||||
// another editor-close event as a result. But we really do
|
// another editor-close event as a result. But we really do
|
||||||
|
@ -778,7 +772,13 @@ export class HistoryService extends Disposable implements IHistoryService {
|
||||||
// to prevent endless loops.
|
// to prevent endless loops.
|
||||||
this.ignoreEditorCloseEvent = true;
|
this.ignoreEditorCloseEvent = true;
|
||||||
try {
|
try {
|
||||||
editorPane = await this.editorService.openEditor(restoredEditor, options);
|
editorPane = await this.editorService.openEditor({
|
||||||
|
...lastClosedEditor.editor,
|
||||||
|
options: {
|
||||||
|
...lastClosedEditor.editor.options,
|
||||||
|
...options
|
||||||
|
}
|
||||||
|
});
|
||||||
} finally {
|
} finally {
|
||||||
this.ignoreEditorCloseEvent = false;
|
this.ignoreEditorCloseEvent = false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue