From 47a6d93693f209da68d24699d66353d3c60aec9e Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Thu, 24 Sep 2020 09:10:14 +0200 Subject: [PATCH] Instantiate text models even if the undo / redo stack for a text model contains foreign elements (#101789) --- .../common/services/modelServiceImpl.ts | 21 ++----------------- .../services/modelUndoRedoParticipant.ts | 10 +++------ 2 files changed, 5 insertions(+), 26 deletions(-) diff --git a/src/vs/editor/common/services/modelServiceImpl.ts b/src/vs/editor/common/services/modelServiceImpl.ts index 576a7dd4ce863..b21a32c25dc63 100644 --- a/src/vs/editor/common/services/modelServiceImpl.ts +++ b/src/vs/editor/common/services/modelServiceImpl.ts @@ -24,9 +24,9 @@ import { RunOnceScheduler } from 'vs/base/common/async'; import { CancellationTokenSource } from 'vs/base/common/cancellation'; import { IThemeService } from 'vs/platform/theme/common/themeService'; import { ILogService } from 'vs/platform/log/common/log'; -import { IUndoRedoService, IUndoRedoElement, IPastFutureElements, ResourceEditStackSnapshot } from 'vs/platform/undoRedo/common/undoRedo'; +import { IUndoRedoService, ResourceEditStackSnapshot } from 'vs/platform/undoRedo/common/undoRedo'; import { StringSHA1 } from 'vs/base/common/hash'; -import { SingleModelEditStackElement, MultiModelEditStackElement, EditStackElement, isEditStackElement } from 'vs/editor/common/model/editStack'; +import { EditStackElement, isEditStackElement } from 'vs/editor/common/model/editStack'; import { Schemas } from 'vs/base/common/network'; import { SemanticTokensProviderStyling, toMultilineTokens2 } from 'vs/editor/common/services/semanticTokensProviderStyling'; @@ -118,23 +118,6 @@ export interface EditStackPastFutureElements { future: EditStackElement[]; } -export function isEditStackPastFutureElements(undoElements: IPastFutureElements): undoElements is EditStackPastFutureElements { - return (isEditStackElements(undoElements.past) && isEditStackElements(undoElements.future)); -} - -function isEditStackElements(elements: IUndoRedoElement[]): elements is EditStackElement[] { - for (const element of elements) { - if (element instanceof SingleModelEditStackElement) { - continue; - } - if (element instanceof MultiModelEditStackElement) { - continue; - } - return false; - } - return true; -} - class DisposedModelInfo { constructor( public readonly uri: URI, diff --git a/src/vs/editor/common/services/modelUndoRedoParticipant.ts b/src/vs/editor/common/services/modelUndoRedoParticipant.ts index 0862ccf8d6e26..6a03af9e80f3d 100644 --- a/src/vs/editor/common/services/modelUndoRedoParticipant.ts +++ b/src/vs/editor/common/services/modelUndoRedoParticipant.ts @@ -6,8 +6,7 @@ import { IModelService } from 'vs/editor/common/services/modelService'; import { ITextModelService } from 'vs/editor/common/services/resolverService'; import { Disposable, IDisposable, dispose } from 'vs/base/common/lifecycle'; -import { IUndoRedoService, UndoRedoElementType } from 'vs/platform/undoRedo/common/undoRedo'; -import { isEditStackPastFutureElements } from 'vs/editor/common/services/modelServiceImpl'; +import { IUndoRedoService } from 'vs/platform/undoRedo/common/undoRedo'; import { IUndoRedoDelegate, MultiModelEditStackElement } from 'vs/editor/common/model/editStack'; export class ModelUndoRedoParticipant extends Disposable implements IUndoRedoDelegate { @@ -23,16 +22,13 @@ export class ModelUndoRedoParticipant extends Disposable implements IUndoRedoDel if (elements.past.length === 0 && elements.future.length === 0) { return; } - if (!isEditStackPastFutureElements(elements)) { - return; - } for (const element of elements.past) { - if (element.type === UndoRedoElementType.Workspace) { + if (element instanceof MultiModelEditStackElement) { element.setDelegate(this); } } for (const element of elements.future) { - if (element.type === UndoRedoElementType.Workspace) { + if (element instanceof MultiModelEditStackElement) { element.setDelegate(this); } }