Skip to content

Commit 99dd406

Browse files
authored
The 3wm editor is not dirty by default anymore and therefore we can tweak the close handler (microsoft#158476)
The 3wm editor is dirty by default anymore and therefore we can tweak the close handler Use default handling when there are no conflicts. Show a message when closing with unhandled conflicts, tweak depending on dirty state fixes microsoft#158405
1 parent 9d0c0b7 commit 99dd406

File tree

2 files changed

+60
-35
lines changed

2 files changed

+60
-35
lines changed

src/vs/workbench/contrib/mergeEditor/browser/mergeEditorInput.ts

Lines changed: 60 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { DisposableStore } from 'vs/base/common/lifecycle';
7-
import { isEqual } from 'vs/base/common/resources';
7+
import { basename, isEqual } from 'vs/base/common/resources';
88
import Severity from 'vs/base/common/severity';
99
import { URI } from 'vs/base/common/uri';
1010
import { ITextModelService } from 'vs/editor/common/services/resolverService';
@@ -234,50 +234,79 @@ class MergeEditorCloseHandler implements IEditorCloseHandler {
234234
return ConfirmResult.SAVE;
235235
}
236236

237-
const actions: string[] = [
238-
someAreDirty ? localize('unhandledConflicts.saveAndIgnore', "Save & Continue with Conflicts") : localize('unhandledConflicts.ignore', "Continue with Conflicts"),
239-
localize('unhandledConflicts.discard', "Discard Merge Changes"),
240-
localize('unhandledConflicts.cancel', "Cancel"),
241-
];
237+
const result = someAreDirty
238+
? await this._confirmDirty(handler)
239+
: await this._confirmNoneDirty(handler);
240+
241+
if (result !== ConfirmResult.CANCEL) {
242+
// save or ignore: in both cases we tell the inputs to ignore unhandled conflicts
243+
// for the dirty state computation.
244+
for (const input of handler) {
245+
input._ignoreUnhandledConflicts = true;
246+
}
247+
}
248+
249+
return result;
250+
}
251+
252+
private async _confirmDirty(handler: MergeEditorCloseHandler[]): Promise<ConfirmResult> {
253+
const isMany = handler.length > 1;
254+
255+
const message = isMany
256+
? localize('messageN', 'Do you want to save the changes you made to {0} files?', handler.length)
257+
: localize('message1', 'Do you want to save the changes you made to {0}?', basename(handler[0]._model.resultTextModel.uri));
258+
242259
const options = {
243260
cancelId: 2,
244-
detail: handler.length > 1
245-
? localize('unhandledConflicts.detailN', 'Merge conflicts in {0} editors will remain unhandled.', handler.length)
246-
: localize('unhandledConflicts.detail1', 'Merge conflicts in this editor will remain unhandled.')
261+
detail: isMany
262+
? localize('detailN', "The files contain unhandled conflicts. Your changes will be lost if you don't save them.")
263+
: localize('detail1', "The file contains unhandled conflicts. Your changes will be lost if you don't save them.")
247264
};
248265

249-
const { choice } = await this._dialogService.show(
250-
Severity.Info,
251-
localize('unhandledConflicts.msg', 'Do you want to continue with unhandled conflicts?'), // 1
252-
actions,
253-
options
254-
);
266+
const actions: string[] = [
267+
localize('saveWithConflict', "Save with Conflicts"),
268+
localize('discard', "Don't save"),
269+
localize('cancel', "Cancel"),
270+
];
271+
272+
const { choice } = await this._dialogService.show(Severity.Info, message, actions, options);
255273

256274
if (choice === options.cancelId) {
257275
// cancel: stay in editor
258276
return ConfirmResult.CANCEL;
277+
} else if (choice === 0) {
278+
// save with conflicts
279+
return ConfirmResult.SAVE;
280+
} else {
281+
// discard changes
282+
return ConfirmResult.DONT_SAVE;
259283
}
284+
}
260285

261-
// save or revert: in both cases we tell the inputs to ignore unhandled conflicts
262-
// for the dirty state computation.
263-
for (const input of handler) {
264-
input._ignoreUnhandledConflicts = true;
265-
}
286+
private async _confirmNoneDirty(handler: MergeEditorCloseHandler[]): Promise<ConfirmResult> {
287+
const isMany = handler.length > 1;
266288

267-
if (choice === 0) {
268-
// conflicts: continue with remaining conflicts
269-
return ConfirmResult.SAVE;
289+
const message = isMany
290+
? localize('conflictN', 'Do you want to close with conflicts in {0} files?', handler.length)
291+
: localize('conflict1', 'Do you want to close with conflicts in {0}?', basename(handler[0]._model.resultTextModel.uri));
270292

271-
} else if (choice === 1) {
272-
// discard: undo all changes and save original (pre-merge) state
273-
for (const input of handler) {
274-
input._model.discardMergeChanges();
275-
}
276-
return ConfirmResult.SAVE;
293+
const options = {
294+
cancelId: 1,
295+
detail: isMany
296+
? localize('detailNotDirtyN', "The files contain unhandled conflicts.")
297+
: localize('detailNotDirty1', "The file contains unhandled conflicts.")
298+
};
299+
300+
const actions = [
301+
localize('closeWithConflicts', "Close with Conflicts"),
302+
localize('cancel', "Cancel"),
303+
];
277304

305+
const { choice } = await this._dialogService.show(Severity.Info, message, actions, options);
306+
if (choice === options.cancelId) {
307+
return ConfirmResult.CANCEL;
278308
} else {
279-
// don't save
280-
return ConfirmResult.DONT_SAVE;
309+
return ConfirmResult.SAVE;
281310
}
282311
}
283312
}

src/vs/workbench/contrib/mergeEditor/browser/model/mergeEditorModel.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,6 @@ export class MergeEditorModel extends EditorModel {
128128
return chunks.join();
129129
}
130130

131-
public discardMergeChanges(): void {
132-
this.resultTextModel.setValue(this.resultSnapshot);
133-
}
134-
135131
constructor(
136132
readonly base: ITextModel,
137133
readonly input1: InputData,

0 commit comments

Comments
 (0)