Skip to content

Commit

Permalink
Merge pull request #154052 from microsoft/joh/3wm-next
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Jul 4, 2022
2 parents 380ad48 + dc5fd78 commit bd9813d
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 21 deletions.
31 changes: 28 additions & 3 deletions src/vs/workbench/contrib/mergeEditor/browser/mergeEditorInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { MergeEditorModel } from 'vs/workbench/contrib/mergeEditor/browser/model
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { AutoSaveMode, IFilesConfigurationService } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService';
import { ILanguageSupport, ITextFileEditorModel, ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { assertType } from 'vs/base/common/types';

export class MergeEditorInputData {
constructor(
Expand Down Expand Up @@ -190,13 +191,15 @@ export class MergeEditorInput extends AbstractTextResourceEditorInput implements
// manual-save: FYI and discard
actions.push(
localize('unhandledConflicts.manualSaveIgnore', "Save and Continue with Conflicts"), // 0
localize('unhandledConflicts.manualSaveNoSave', "Don't Save") // 1
localize('unhandledConflicts.discard', "Discard Merge Changes"), // 1
localize('unhandledConflicts.manualSaveNoSave', "Don't Save"), // 2
);

} else {
// auto-save: only FYI
actions.push(
localize('unhandledConflicts.ignore', "Continue with Conflicts"), // 0
localize('unhandledConflicts.discard', "Discard Merge Changes"), // 1
);
}

Expand Down Expand Up @@ -224,10 +227,32 @@ export class MergeEditorInput extends AbstractTextResourceEditorInput implements
if (choice === 0) {
// conflicts: continue with remaining conflicts
return ConfirmResult.SAVE;

} else if (choice === 1) {
// discard: undo all changes and save original (pre-merge) state
for (const input of inputs) {
input._discardMergeChanges();
}
return ConfirmResult.SAVE;

} else {
// don't save
return ConfirmResult.DONT_SAVE;
}
}

private _discardMergeChanges(): void {
assertType(this._model !== undefined);

// don't save
return ConfirmResult.DONT_SAVE;
const chunks: string[] = [];
while (true) {
const chunk = this._model.resultSnapshot.read();
if (chunk === null) {
break;
}
chunks.push(chunk);
}
this._model.result.setValue(chunks.join());
}

setLanguageId(languageId: string, _setExplicitly?: boolean): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { CompareResult, equals } from 'vs/base/common/arrays';
import { BugIndicatingError } from 'vs/base/common/errors';
import { ILanguageService } from 'vs/editor/common/languages/language';
import { ITextModel } from 'vs/editor/common/model';
import { ITextModel, ITextSnapshot } from 'vs/editor/common/model';
import { IModelService } from 'vs/editor/common/services/model';
import { EditorModel } from 'vs/workbench/common/editor/editorModel';
import { autorunHandleChanges, derivedObservable, IObservable, IReader, ITransaction, keepAlive, ObservableValue, transaction, waitForState } from 'vs/workbench/contrib/audioCues/browser/observable';
Expand Down Expand Up @@ -120,6 +120,8 @@ export class MergeEditorModel extends EditorModel {
);
});

readonly resultSnapshot: ITextSnapshot;

constructor(
readonly base: ITextModel,
readonly input1: ITextModel,
Expand All @@ -137,6 +139,7 @@ export class MergeEditorModel extends EditorModel {
) {
super();

this.resultSnapshot = result.createSnapshot();
this._register(keepAlive(this.modifiedBaseRangeStateStores));
this._register(keepAlive(this.modifiedBaseRangeHandlingStateStores));
this._register(keepAlive(this.input1ResultMapping));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { h } from 'vs/base/browser/dom';
import { h, reset } from 'vs/base/browser/dom';
import { IView, IViewSize } from 'vs/base/browser/ui/grid/grid';
import { IconLabel } from 'vs/base/browser/ui/iconLabel/iconLabel';
import { renderLabelWithIcons } from 'vs/base/browser/ui/iconLabel/iconLabels';
import { Emitter, Event } from 'vs/base/common/event';
import { Disposable } from 'vs/base/common/lifecycle';
import { IEditorContributionDescription } from 'vs/editor/browser/editorExtensions';
Expand All @@ -24,7 +24,11 @@ export abstract class CodeEditorView extends Disposable {
readonly model = this._viewModel.map(m => m?.model);

protected readonly htmlElements = h('div.code-view', [
h('div.title', { $: 'title' }),
h('div.title', [
h('span.title', { $: 'title' }),
h('span.description', { $: 'description' }),
h('span.detail', { $: 'detail' }),
]),
h('div.container', [
h('div.gutter', { $: 'gutterDiv' }),
h('div', { $: 'editor' }),
Expand Down Expand Up @@ -53,9 +57,6 @@ export abstract class CodeEditorView extends Disposable {
// snap?: boolean | undefined;
};

private readonly _title = new IconLabel(this.htmlElements.title, { supportIcons: true });
protected readonly _detail = new IconLabel(this.htmlElements.title, { supportIcons: true });

public readonly editor = this.instantiationService.createInstance(
CodeEditorWidget,
this.htmlElements.editor,
Expand Down Expand Up @@ -100,8 +101,10 @@ export abstract class CodeEditorView extends Disposable {
detail: string | undefined
): void {
this.editor.setModel(textModel);
this._title.setLabel(title, description);
this._detail.setLabel('', detail);

reset(this.htmlElements.title, ...renderLabelWithIcons(title));
reset(this.htmlElements.description, ...(description ? renderLabelWithIcons(description) : []));
reset(this.htmlElements.detail, ...(detail ? renderLabelWithIcons(detail) : []));

this._viewModel.set(viewModel, undefined);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,18 @@ export class ResultCodeEditorView extends CodeEditorView {
}
const count = model.unhandledConflictsCount.read(reader);

this._detail.setLabel(count === 1
this.htmlElements.detail.innerText = count === 1
? localize(
'mergeEditor.remainingConflicts',
'{0} Remaining Conflict',
'{0} Conflict Remaining',
count
)
: localize(
'mergeEditor.remainingConflict',
'{0} Remaining Conflicts',
'{0} Conflicts Remaining ',
count
));
);

}, 'update label'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,27 @@
height: 30px;
display: flex;
align-content: center;
justify-content: space-between;
}

.monaco-workbench .merge-editor .code-view > .title .monaco-icon-label {
margin: auto 0;
.monaco-workbench .merge-editor .code-view > .title>SPAN {
align-self: center;
text-overflow: ellipsis;
overflow: hidden;
padding-right: 6px;
}

.monaco-workbench .merge-editor .code-view > .title>SPAN.title {
flex-shrink: 0;
}

.monaco-workbench .merge-editor .code-view > .title>SPAN.description {
opacity: 0.7;
font-size: 90%;
}

.monaco-workbench .merge-editor .code-view > .title>SPAN.detail {
margin-left: auto;
flex-shrink: 0;
}

.monaco-workbench .merge-editor .code-view > .container {
Expand Down
17 changes: 15 additions & 2 deletions src/vs/workbench/contrib/mergeEditor/browser/view/mergeEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { IAction } from 'vs/base/common/actions';
import { CancellationToken } from 'vs/base/common/cancellation';
import { Color } from 'vs/base/common/color';
import { BugIndicatingError } from 'vs/base/common/errors';
import { Emitter, Event } from 'vs/base/common/event';
import { DisposableStore, MutableDisposable } from 'vs/base/common/lifecycle';
import { isEqual } from 'vs/base/common/resources';
import { URI } from 'vs/base/common/uri';
Expand Down Expand Up @@ -85,8 +86,6 @@ export class MergeEditor extends AbstractTextEditor<IMergeEditorViewState> {
private readonly _sessionDisposables = new DisposableStore();

private _grid!: Grid<IView>;


private readonly input1View = this._register(this.instantiation.createInstance(InputCodeEditorView, 1));
private readonly input2View = this._register(this.instantiation.createInstance(InputCodeEditorView, 2));
private readonly inputResultView = this._register(this.instantiation.createInstance(ResultCodeEditorView));
Expand Down Expand Up @@ -209,6 +208,19 @@ export class MergeEditor extends AbstractTextEditor<IMergeEditorViewState> {
super.dispose();
}

// --- layout constraints

private readonly _onDidChangeSizeConstraints = new Emitter<void>();
override readonly onDidChangeSizeConstraints: Event<void> = this._onDidChangeSizeConstraints.event;

override get minimumWidth() {
return this._layoutMode.value === 'mixed'
? this.input1View.view.minimumWidth + this.input1View.view.minimumWidth
: this.input1View.view.minimumWidth + this.input1View.view.minimumWidth + this.inputResultView.view.minimumWidth;
}

// ---

override getTitle(): string {
if (this.input) {
return this.input.getName();
Expand Down Expand Up @@ -454,6 +466,7 @@ export class MergeEditor extends AbstractTextEditor<IMergeEditorViewState> {
}
this._layoutMode.value = newValue;
this._ctxUsesColumnLayout.set(newValue);
this._onDidChangeSizeConstraints.fire();
}

private _applyViewState(state: IMergeEditorViewState | undefined) {
Expand Down

0 comments on commit bd9813d

Please sign in to comment.