Skip to content

Commit

Permalink
tweak message when closing dirty and conflicting merge editor
Browse files Browse the repository at this point in the history
fyi @bpasero this ensures the close handler is always called with `IEditorIdentifier[]`

re #152841
  • Loading branch information
jrieken committed Jul 14, 2022
1 parent e06f679 commit 90a6462
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/vs/workbench/browser/parts/editor/editorGroupView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1555,7 +1555,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView {

// Let editor handle confirmation if implemented
if (typeof editor.closeHandler?.confirm === 'function') {
confirmation = await editor.closeHandler.confirm();
confirmation = await editor.closeHandler.confirm([{ editor, groupId: this.id }]);
}

// Show a file specific confirmation
Expand Down
6 changes: 3 additions & 3 deletions src/vs/workbench/common/editor/editorInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ export interface IEditorCloseHandler {
* should be used besides dirty state, this method should be
* implemented to show a different dialog.
*
* @param editors if more than one editor is closed, will pass in
* each editor of the same kind to be able to show a combined dialog.
* @param editors All editors of the same kind that are being closed. Should be used
* to show a combined dialog.
*/
confirm(editors?: ReadonlyArray<IEditorIdentifier>): Promise<ConfirmResult>;
confirm(editors: ReadonlyArray<IEditorIdentifier>): Promise<ConfirmResult>;
}

/**
Expand Down
18 changes: 11 additions & 7 deletions src/vs/workbench/contrib/mergeEditor/browser/mergeEditorInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,21 +173,25 @@ class MergeEditorCloseHandler implements IEditorCloseHandler {
return !this._ignoreUnhandledConflicts && this._model.hasUnhandledConflicts.get();
}

async confirm(editors?: readonly IEditorIdentifier[] | undefined): Promise<ConfirmResult> {
async confirm(editors: readonly IEditorIdentifier[]): Promise<ConfirmResult> {

const handler: MergeEditorCloseHandler[] = [this];
editors?.forEach(candidate => candidate.editor.closeHandler instanceof MergeEditorCloseHandler && handler.push(candidate.editor.closeHandler));
const handler: MergeEditorCloseHandler[] = [];
let someAreDirty = false;

const inputsWithUnhandledConflicts = handler
.filter(input => input._model && input._model.hasUnhandledConflicts.get());
for (const { editor } of editors) {
if (editor.closeHandler instanceof MergeEditorCloseHandler && editor.closeHandler._model.hasUnhandledConflicts.get()) {
handler.push(editor.closeHandler);
someAreDirty = someAreDirty || editor.isDirty();
}
}

if (inputsWithUnhandledConflicts.length === 0) {
if (handler.length === 0) {
// shouldn't happen
return ConfirmResult.SAVE;
}

const actions: string[] = [
localize('unhandledConflicts.ignore', "Continue with Conflicts"),
someAreDirty ? localize('unhandledConflicts.saveAndIgnore', "Save & Continue with Conflicts") : localize('unhandledConflicts.ignore', "Continue with Conflicts"),
localize('unhandledConflicts.discard', "Discard Merge Changes"),
localize('unhandledConflicts.cancel', "Cancel"),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class TerminalEditorInput extends EditorInput implements IEditorCloseHand
return false;
}

async confirm(terminals?: ReadonlyArray<IEditorIdentifier>): Promise<ConfirmResult> {
async confirm(terminals: ReadonlyArray<IEditorIdentifier>): Promise<ConfirmResult> {
const { choice } = await this._dialogService.show(
Severity.Warning,
localize('confirmDirtyTerminal.message', "Do you want to terminate running processes?"),
Expand All @@ -110,7 +110,7 @@ export class TerminalEditorInput extends EditorInput implements IEditorCloseHand
],
{
cancelId: 1,
detail: terminals && terminals.length > 1 ?
detail: terminals.length > 1 ?
terminals.map(terminal => terminal.editor.getName()).join('\n') + '\n\n' + localize('confirmDirtyTerminals.detail', "Closing will terminate the running processes in the terminals.") :
localize('confirmDirtyTerminal.detail', "Closing will terminate the running processes in this terminal.")
}
Expand Down

0 comments on commit 90a6462

Please sign in to comment.