Skip to content

Commit 15a7e46

Browse files
authored
Merge pull request microsoft#199623 from gjsjohnmurray/do-199598
Multi-diff editor: add `Expand All Diffs` action
2 parents 84de654 + 4845eeb commit 15a7e46

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ export class MultiDiffEditorViewModel extends Disposable {
3535
});
3636
}
3737

38+
public expandAll(): void {
39+
transaction(tx => {
40+
for (const d of this.items.get()) {
41+
d.collapsed.set(false, tx);
42+
}
43+
});
44+
}
45+
3846
constructor(
3947
private readonly _model: IMultiDiffEditorModel,
4048
private readonly _instantiationService: IInstantiationService,

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ export class MultiDiffEditorWidgetImpl extends Disposable {
9999

100100
this._contextKeyService.createKey(EditorContextKeys.inMultiDiffEditor.key, true);
101101

102+
const ctxAllCollapsed = this._parentContextKeyService.createKey<boolean>(EditorContextKeys.multiDiffEditorAllCollapsed.key, false);
103+
this._register(autorun((reader) => {
104+
const viewModel = this._viewModel.read(reader);
105+
if (viewModel) {
106+
const allCollapsed = viewModel.items.read(reader).every(item => item.collapsed.read(reader));
107+
ctxAllCollapsed.set(allCollapsed);
108+
}
109+
}));
110+
102111
this._register(autorun((reader) => {
103112
const lastActiveDiffItem = this.lastActiveDiffItem.read(reader);
104113
transaction(tx => {

src/vs/editor/common/editorContextKeys.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export namespace EditorContextKeys {
2828
export const inDiffEditor = new RawContextKey<boolean>('inDiffEditor', false, nls.localize('inDiffEditor', "Whether the context is a diff editor"));
2929
export const isEmbeddedDiffEditor = new RawContextKey<boolean>('isEmbeddedDiffEditor', false, nls.localize('isEmbeddedDiffEditor', "Whether the context is an embedded diff editor"));
3030
export const inMultiDiffEditor = new RawContextKey<boolean>('inMultiDiffEditor', false, nls.localize('inMultiDiffEditor', "Whether the context is a multi diff editor"));
31+
export const multiDiffEditorAllCollapsed = new RawContextKey<boolean>('multiDiffEditorAllCollapsed', undefined, nls.localize('multiDiffEditorAllCollapsed', "Whether all files in multi diff editor are collapsed"));
3132
export const hasChanges = new RawContextKey<boolean>('diffEditorHasChanges', false, nls.localize('diffEditorHasChanges', "Whether the diff editor has changes"));
3233

3334
export const comparingMovedCode = new RawContextKey<boolean>('comparingMovedCode', false, nls.localize('comparingMovedCode', "Whether a moved code block is selected for comparison"));

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

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ export class CollapseAllAction extends Action2 {
135135
id: 'multiDiffEditor.collapseAll',
136136
title: { value: localize('collapseAllDiffs', "Collapse All Diffs"), original: 'Collapse All Diffs' },
137137
icon: Codicon.collapseAll,
138-
precondition: ContextKeyExpr.equals('activeEditor', MultiDiffEditor.ID),
138+
precondition: ContextKeyExpr.and(ContextKeyExpr.equals('activeEditor', MultiDiffEditor.ID), ContextKeyExpr.not('multiDiffEditorAllCollapsed')),
139139
menu: {
140-
when: ContextKeyExpr.equals('activeEditor', MultiDiffEditor.ID),
140+
when: ContextKeyExpr.and(ContextKeyExpr.equals('activeEditor', MultiDiffEditor.ID), ContextKeyExpr.not('multiDiffEditorAllCollapsed')),
141141
id: MenuId.EditorTitle,
142142
group: 'navigation',
143143
},
@@ -156,8 +156,36 @@ export class CollapseAllAction extends Action2 {
156156
}
157157
}
158158

159+
export class ExpandAllAction extends Action2 {
160+
constructor() {
161+
super({
162+
id: 'multiDiffEditor.expandAll',
163+
title: { value: localize('ExpandAllDiffs', "Expand All Diffs"), original: 'Expand All Diffs' },
164+
icon: Codicon.expandAll,
165+
precondition: ContextKeyExpr.and(ContextKeyExpr.equals('activeEditor', MultiDiffEditor.ID), ContextKeyExpr.has('multiDiffEditorAllCollapsed')),
166+
menu: {
167+
when: ContextKeyExpr.and(ContextKeyExpr.equals('activeEditor', MultiDiffEditor.ID), ContextKeyExpr.has('multiDiffEditorAllCollapsed')),
168+
id: MenuId.EditorTitle,
169+
group: 'navigation',
170+
},
171+
f1: true,
172+
});
173+
}
174+
175+
async run(accessor: ServicesAccessor, ...args: any[]): Promise<void> {
176+
const editorService = accessor.get(IEditorService);
177+
const activeEditor = editorService.activeEditor;
178+
179+
if (activeEditor instanceof MultiDiffEditorInput) {
180+
const viewModel = await activeEditor.getViewModel();
181+
viewModel.expandAll();
182+
}
183+
}
184+
}
185+
159186
registerAction2(GoToFileAction);
160187
registerAction2(CollapseAllAction);
188+
registerAction2(ExpandAllAction);
161189

162190
Registry.as<IConfigurationRegistry>(Extensions.Configuration).registerConfiguration({
163191
properties: {

0 commit comments

Comments
 (0)