Skip to content

Commit 44b0291

Browse files
author
Benjamin Pasero
committed
untitled - do not update model with initial value if existing
1 parent 26510e7 commit 44b0291

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

src/vs/workbench/common/editor/textEditorModel.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,15 @@ export class BaseTextEditorModel extends EditorModel implements ITextEditorModel
141141
/**
142142
* Updates the text editor model with the provided value. If the value is the same as the model has, this is a no-op.
143143
*/
144-
protected updateTextEditorModel(newValue: ITextBufferFactory, preferredMode?: string): void {
144+
protected updateTextEditorModel(newValue?: ITextBufferFactory, preferredMode?: string): void {
145145
if (!this.isResolved()) {
146146
return;
147147
}
148148

149149
// contents
150-
this.modelService.updateModel(this.textEditorModel, newValue);
150+
if (newValue) {
151+
this.modelService.updateModel(this.textEditorModel, newValue);
152+
}
151153

152154
// mode (only if specific and changed)
153155
if (preferredMode && preferredMode !== PLAINTEXT_MODE_ID && this.textEditorModel.getModeId() !== preferredMode) {

src/vs/workbench/services/untitled/common/untitledTextEditorModel.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ export interface IUntitledTextEditorModel extends ITextEditorModel, IModeSupport
5656

5757
/**
5858
* Updates the value of the untitled model optionally allowing to ignore dirty.
59+
* The model must be resolved for this method to work.
5960
*/
60-
setValue(value: string, ignoreDirty?: boolean): void;
61+
setValue(this: IResolvedTextEditorModel, value: string, ignoreDirty?: boolean): void;
6162
}
6263

6364
export class UntitledTextEditorModel extends BaseTextEditorModel implements IUntitledTextEditorModel {
@@ -259,9 +260,11 @@ export class UntitledTextEditorModel extends BaseTextEditorModel implements IUnt
259260
this.createTextEditorModel(untitledContents, this.resource, this.preferredMode);
260261
}
261262

262-
// Otherwise update
263+
// Otherwise: the untitled model already exists and we must assume
264+
// that the value of the model was changed by the user. As such we
265+
// do not update the contents, only the mode if configured.
263266
else {
264-
this.updateTextEditorModel(untitledContents, this.preferredMode);
267+
this.updateTextEditorModel(undefined, this.preferredMode);
265268
}
266269

267270
// Figure out encoding now that model is present

0 commit comments

Comments
 (0)