Skip to content

Commit 3d990fc

Browse files
authored
Merge pull request microsoft#199064 from gjsjohnmurray/do-198248
Add 'Collapse All Diffs' action button to multi-diff editor
2 parents cb8e8a9 + bc1cc38 commit 3d990fc

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

src/vs/editor/browser/widget/multiDiffEditorWidget/multiDiffEditorViewModel.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { Disposable } from 'vs/base/common/lifecycle';
7-
import { derivedWithStore, observableFromEvent, observableValue } from 'vs/base/common/observable';
7+
import { derivedWithStore, observableFromEvent, observableValue, transaction } from 'vs/base/common/observable';
88
import { DiffEditorOptions } from 'vs/editor/browser/widget/diffEditor/diffEditorOptions';
99
import { DiffEditorViewModel } from 'vs/editor/browser/widget/diffEditor/diffEditorViewModel';
1010
import { IDocumentDiffItem, IMultiDiffEditorModel, LazyPromise } from 'vs/editor/browser/widget/multiDiffEditorWidget/model';
@@ -27,6 +27,14 @@ export class MultiDiffEditorViewModel extends Disposable {
2727
}
2828
}
2929

30+
public collapseAll(): void {
31+
transaction(tx => {
32+
for (const d of this.items.get()) {
33+
d.collapsed.set(true, tx);
34+
}
35+
});
36+
}
37+
3038
constructor(
3139
private readonly _model: IMultiDiffEditorModel,
3240
private readonly _instantiationService: IInstantiationService,

src/vs/workbench/contrib/multiDiffEditor/browser/multiDiffEditor.contribution.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { Action2, MenuId, registerAction2 } from 'vs/platform/actions/common/act
2323
import { URI } from 'vs/base/common/uri';
2424
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
2525
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
26+
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
2627
import { Extensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry';
2728

2829
class MultiDiffEditorResolverContribution extends Disposable {
@@ -128,7 +129,34 @@ export class GoToFileAction extends Action2 {
128129
}
129130
}
130131

132+
export class CollapseAllAction extends Action2 {
133+
constructor() {
134+
super({
135+
id: 'multiDiffEditor.collapseAll',
136+
title: { value: localize('collapseAllDiffs', "Collapse All Diffs"), original: 'Collapse All Diffs' },
137+
icon: Codicon.collapseAll,
138+
precondition: ContextKeyExpr.equals('activeEditor', MultiDiffEditor.ID),
139+
menu: {
140+
when: ContextKeyExpr.equals('activeEditor', MultiDiffEditor.ID),
141+
id: MenuId.EditorTitle,
142+
group: 'navigation',
143+
},
144+
});
145+
}
146+
147+
async run(accessor: ServicesAccessor, ...args: any[]): Promise<void> {
148+
const editorService = accessor.get(IEditorService);
149+
const activeEditor = editorService.activeEditor;
150+
151+
if (activeEditor instanceof MultiDiffEditorInput) {
152+
const viewModel = await activeEditor.getViewModel();
153+
viewModel.collapseAll();
154+
}
155+
}
156+
}
157+
131158
registerAction2(GoToFileAction);
159+
registerAction2(CollapseAllAction);
132160

133161
Registry.as<IConfigurationRegistry>(Extensions.Configuration).registerConfiguration({
134162
properties: {

src/vs/workbench/contrib/multiDiffEditor/browser/multiDiffEditor.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,18 @@ import { MultiDiffEditorInput } from 'vs/workbench/contrib/multiDiffEditor/brows
2323
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
2424
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
2525
import { URI } from 'vs/base/common/uri';
26+
import { MultiDiffEditorViewModel } from 'vs/editor/browser/widget/multiDiffEditorWidget/multiDiffEditorViewModel';
2627

2728
export class MultiDiffEditor extends AbstractEditorWithViewState<IMultiDiffEditorViewState> {
2829
static readonly ID = 'multiDiffEditor';
2930

3031
private _multiDiffEditorWidget: MultiDiffEditorWidget | undefined = undefined;
32+
private _viewModel: MultiDiffEditorViewModel | undefined;
33+
34+
public get viewModel(): MultiDiffEditorViewModel | undefined {
35+
return this._viewModel;
36+
}
37+
3138

3239
constructor(
3340
@IInstantiationService instantiationService: InstantiationService,
@@ -65,8 +72,8 @@ export class MultiDiffEditor extends AbstractEditorWithViewState<IMultiDiffEdito
6572

6673
override async setInput(input: MultiDiffEditorInput, options: IEditorOptions | undefined, context: IEditorOpenContext, token: CancellationToken): Promise<void> {
6774
await super.setInput(input, options, context, token);
68-
const vm = await input.getViewModel();
69-
this._multiDiffEditorWidget!.setViewModel(vm);
75+
this._viewModel = await input.getViewModel();
76+
this._multiDiffEditorWidget!.setViewModel(this._viewModel);
7077

7178
const viewState = this.loadEditorViewState(input, context);
7279
if (viewState) {

0 commit comments

Comments
 (0)