Skip to content

Commit e77342e

Browse files
authored
Add expand/collapse all commands for comments (microsoft#159674)
Part of microsoft#158316
1 parent a661cd0 commit e77342e

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

src/vs/workbench/contrib/comments/browser/commentThreadZoneWidget.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,14 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
256256
return Promise.resolve();
257257
}
258258

259+
public expand(): Promise<void> {
260+
this._commentThread.collapsibleState = languages.CommentThreadCollapsibleState.Expanded;
261+
const lineNumber = this._commentThread.range.startLineNumber;
262+
263+
this.show({ lineNumber, column: 1 }, 2);
264+
return Promise.resolve();
265+
}
266+
259267
public getGlyphPosition(): number {
260268
if (this._commentGlyph) {
261269
return this._commentGlyph.getPosition().position!.lineNumber;

src/vs/workbench/contrib/comments/browser/commentsEditorContribution.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,18 @@ export class CommentController implements IEditorContribution {
517517
}
518518
}
519519

520+
public collapseAll(): void {
521+
for (const widget of this._commentWidgets) {
522+
widget.collapse();
523+
}
524+
}
525+
526+
public expandAll(): void {
527+
for (const widget of this._commentWidgets) {
528+
widget.expand();
529+
}
530+
}
531+
520532
public nextCommentThread(): void {
521533
this._findNearestCommentThread();
522534
}
@@ -1063,6 +1075,40 @@ MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
10631075
when: ActiveCursorHasCommentingRange
10641076
});
10651077

1078+
const COLLAPSE_ALL_COMMENT_COMMAND = 'workbench.action.collapseAllComments';
1079+
CommandsRegistry.registerCommand({
1080+
id: COLLAPSE_ALL_COMMENT_COMMAND,
1081+
handler: (accessor) => {
1082+
return getActiveController(accessor)?.collapseAll();
1083+
}
1084+
});
1085+
1086+
MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
1087+
command: {
1088+
id: COLLAPSE_ALL_COMMENT_COMMAND,
1089+
title: nls.localize('comments.collapseAll', "Collapse All Comments"),
1090+
category: 'Comments'
1091+
},
1092+
when: WorkspaceHasCommenting
1093+
});
1094+
1095+
const EXPAND_ALL_COMMENT_COMMAND = 'workbench.action.expandAllComments';
1096+
CommandsRegistry.registerCommand({
1097+
id: EXPAND_ALL_COMMENT_COMMAND,
1098+
handler: (accessor) => {
1099+
return getActiveController(accessor)?.expandAll();
1100+
}
1101+
});
1102+
1103+
MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
1104+
command: {
1105+
id: EXPAND_ALL_COMMENT_COMMAND,
1106+
title: nls.localize('comments.expandAll', "Expand All Comments"),
1107+
category: 'Comments'
1108+
},
1109+
when: WorkspaceHasCommenting
1110+
});
1111+
10661112
KeybindingsRegistry.registerCommandAndKeybindingRule({
10671113
id: 'workbench.action.submitComment',
10681114
weight: KeybindingWeight.EditorContrib,
@@ -1108,6 +1154,19 @@ export function getActiveEditor(accessor: ServicesAccessor): IActiveCodeEditor |
11081154
return activeTextEditorControl;
11091155
}
11101156

1157+
function getActiveController(accessor: ServicesAccessor): CommentController | undefined {
1158+
const activeEditor = getActiveEditor(accessor);
1159+
if (!activeEditor) {
1160+
return undefined;
1161+
}
1162+
1163+
const controller = CommentController.get(activeEditor);
1164+
if (!controller) {
1165+
return undefined;
1166+
}
1167+
return controller;
1168+
}
1169+
11111170
registerThemingParticipant((theme, collector) => {
11121171
const peekViewBackground = theme.getColor(peekViewResultsBackground);
11131172
if (peekViewBackground) {

0 commit comments

Comments
 (0)