commentsEditorContribution.ts 21.4 KB
Newer Older
P
Peng Lyu 已提交
1 2 3 4 5 6
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
'use strict';

P
Peng Lyu 已提交
7
import 'vs/css!./media/review';
P
Peng Lyu 已提交
8
import * as nls from 'vs/nls';
9
import { $ } from 'vs/base/browser/dom';
P
Peng Lyu 已提交
10
import { findFirstInSorted } from 'vs/base/common/arrays';
11
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
P
Peng Lyu 已提交
12
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
13
import { ICodeEditor, IEditorMouseEvent, IViewZone, MouseTargetType } from 'vs/editor/browser/editorBrowser';
P
Peng Lyu 已提交
14
import { registerEditorContribution, EditorAction, registerEditorAction } from 'vs/editor/browser/editorExtensions';
P
Peng Lyu 已提交
15 16
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { EmbeddedCodeEditorWidget } from 'vs/editor/browser/widget/embeddedCodeEditorWidget';
17
import { IEditorContribution } from 'vs/editor/common/editorCommon';
P
Peng Lyu 已提交
18
import { IRange } from 'vs/editor/common/core/range';
19
import * as modes from 'vs/editor/common/modes';
M
Miguel Solorio 已提交
20
import { peekViewResultsBackground, peekViewResultsSelectionBackground, peekViewTitleBackground } from 'vs/editor/contrib/referenceSearch/referencesWidget';
21
import { IContextKey, IContextKeyService, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
P
Peng Lyu 已提交
22
import { ServicesAccessor, IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
23
import { KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
24
import { editorForeground, registerColor } from 'vs/platform/theme/common/colorRegistry';
25
import { IThemeService, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
26
import { CommentThreadCollapsibleState } from 'vs/workbench/api/node/extHostTypes';
P
Peng Lyu 已提交
27
import { ReviewZoneWidget, COMMENTEDITOR_DECORATION_KEY } from 'vs/workbench/parts/comments/electron-browser/commentThreadWidget';
28
import { ICommentService } from 'vs/workbench/parts/comments/electron-browser/commentService';
P
Peng Lyu 已提交
29 30
import { IModelService } from 'vs/editor/common/services/modelService';
import { IModeService } from 'vs/editor/common/services/modeService';
31
import { IOpenerService } from 'vs/platform/opener/common/opener';
32 33 34 35
import { ModelDecorationOptions } from 'vs/editor/common/model/textModel';
import { IModelDecorationOptions } from 'vs/editor/common/model';
import { Color, RGBA } from 'vs/base/common/color';
import { IMarginData } from 'vs/editor/browser/controller/mouseTarget';
36
import { INotificationService } from 'vs/platform/notification/common/notification';
P
Peng Lyu 已提交
37 38

export const ctxReviewPanelVisible = new RawContextKey<boolean>('reviewPanelVisible', false);
39

P
Peng Lyu 已提交
40 41 42 43 44 45 46 47 48 49 50
export const ID = 'editor.contrib.review';

export class ReviewViewZone implements IViewZone {
	public readonly afterLineNumber: number;
	public readonly domNode: HTMLElement;
	private callback: (top: number) => void;

	constructor(afterLineNumber: number, onDomNodeTop: (top: number) => void) {
		this.afterLineNumber = afterLineNumber;
		this.callback = onDomNodeTop;

51
		this.domNode = $('.review-viewzone');
P
Peng Lyu 已提交
52 53 54 55 56 57 58
	}

	onDomNodeTop(top: number): void {
		this.callback(top);
	}
}

P
Peng Lyu 已提交
59
const overviewRulerDefault = new Color(new RGBA(197, 197, 197, 1));
60

61
export const overviewRulerCommentingRangeForeground = registerColor('editorGutter.commentRangeForeground', { dark: overviewRulerDefault, light: overviewRulerDefault, hc: overviewRulerDefault }, nls.localize('editorGutterCommentRangeForeground', 'Editor gutter decoration color for commenting ranges.'));
62

P
Peng Lyu 已提交
63 64 65
class CommentingRangeDecoration {
	private _decorationId: string;

66 67 68 69
	get id(): string {
		return this._decorationId;
	}

P
Peng Lyu 已提交
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
	constructor(private _editor: ICodeEditor, private _ownerId: number, private _range: IRange, private _reply: modes.Command, commentingOptions: ModelDecorationOptions) {
		const startLineNumber = _range.startLineNumber;
		const endLineNumber = _range.endLineNumber;
		let commentingRangeDecorations = [{
			range: {
				startLineNumber: startLineNumber, startColumn: 1,
				endLineNumber: endLineNumber, endColumn: 1
			},
			options: commentingOptions
		}];

		let model = this._editor.getModel();
		if (model) {
			this._decorationId = model.deltaDecorations([this._decorationId], commentingRangeDecorations)[0];
		}
	}

	getCommentAction(): { replyCommand: modes.Command, ownerId: number } {
		return {
			replyCommand: this._reply,
			ownerId: this._ownerId
		};
	}

	getOriginalRange() {
		return this._range;
	}

	getActiveRange() {
		return this._editor.getModel().getDecorationRange(this._decorationId);
	}
}
102 103 104 105 106 107 108
class CommentingRangeDecorator {

	static createDecoration(className: string, foregroundColor: string, options: { gutter: boolean, overview: boolean }): ModelDecorationOptions {
		const decorationOptions: IModelDecorationOptions = {
			isWholeLine: true,
		};

109
		decorationOptions.linesDecorationsClassName = `comment-range-glyph ${className}`;
110 111 112 113
		return ModelDecorationOptions.createDynamic(decorationOptions);
	}

	private commentingOptions: ModelDecorationOptions;
114
	public commentsOptions: ModelDecorationOptions;
P
Peng Lyu 已提交
115
	private commentingRangeDecorations: CommentingRangeDecoration[] = [];
116 117 118 119 120 121
	private disposables: IDisposable[] = [];

	constructor(
	) {
		const options = { gutter: true, overview: false };
		this.commentingOptions = CommentingRangeDecorator.createDecoration('comment-diff-added', overviewRulerCommentingRangeForeground, options);
122
		this.commentsOptions = CommentingRangeDecorator.createDecoration('comment-thread', overviewRulerCommentingRangeForeground, options);
123 124
	}

P
Peng Lyu 已提交
125
	update(editor: ICodeEditor, commentInfos: modes.CommentInfo[]) {
126 127 128 129 130
		let model = editor.getModel();
		if (!model) {
			return;
		}

P
Peng Lyu 已提交
131 132 133 134 135 136 137
		let commentingRangeDecorations = [];
		for (let i = 0; i < commentInfos.length; i++) {
			let info = commentInfos[i];
			info.commentingRanges.forEach(range => {
				commentingRangeDecorations.push(new CommentingRangeDecoration(editor, info.owner, range, info.reply, this.commentingOptions));
			});
		}
138

139 140 141
		let oldDecorations = this.commentingRangeDecorations.map(decoration => decoration.id);
		editor.deltaDecorations(oldDecorations, []);

P
Peng Lyu 已提交
142
		this.commentingRangeDecorations = commentingRangeDecorations;
143 144
	}

P
Peng Lyu 已提交
145
	getMatchedCommentAction(line: number) {
146
		for (let i = 0; i < this.commentingRangeDecorations.length; i++) {
P
Peng Lyu 已提交
147 148 149 150 151
			let range = this.commentingRangeDecorations[i].getActiveRange();

			if (range.startLineNumber <= line && line <= range.endLineNumber) {
				return this.commentingRangeDecorations[i].getCommentAction();
			}
152 153
		}

P
Peng Lyu 已提交
154
		return null;
155 156 157 158
	}

	dispose(): void {
		this.disposables = dispose(this.disposables);
159
		this.commentingRangeDecorations = [];
160 161 162
	}
}

P
Peng Lyu 已提交
163 164 165 166
export class ReviewController implements IEditorContribution {
	private globalToDispose: IDisposable[];
	private localToDispose: IDisposable[];
	private editor: ICodeEditor;
R
Rachel Macfarlane 已提交
167 168
	private _newCommentWidget: ReviewZoneWidget;
	private _commentWidgets: ReviewZoneWidget[];
P
Peng Lyu 已提交
169
	private _reviewPanelVisible: IContextKey<boolean>;
170
	private _commentInfos: modes.CommentInfo[];
171 172 173
	// private _hasSetComments: boolean;
	private _commentingRangeDecorator: CommentingRangeDecorator;
	private mouseDownInfo: { lineNumber: number } | null = null;
174
	private _commentingRangeSpaceReserved = false;
175

P
Peng Lyu 已提交
176 177 178

	constructor(
		editor: ICodeEditor,
179
		@IContextKeyService contextKeyService: IContextKeyService,
180
		@IThemeService private themeService: IThemeService,
181
		@ICommentService private commentService: ICommentService,
182
		@INotificationService private notificationService: INotificationService,
P
Peng Lyu 已提交
183 184 185 186
		@IInstantiationService private instantiationService: IInstantiationService,
		@IModeService private modeService: IModeService,
		@IModelService private modelService: IModelService,
		@ICodeEditorService private codeEditorService: ICodeEditorService,
187
		@IOpenerService private openerService: IOpenerService
P
Peng Lyu 已提交
188 189 190 191
	) {
		this.editor = editor;
		this.globalToDispose = [];
		this.localToDispose = [];
192
		this._commentInfos = [];
R
Rachel Macfarlane 已提交
193 194
		this._commentWidgets = [];
		this._newCommentWidget = null;
195
		// this._hasSetComments = false;
P
Peng Lyu 已提交
196 197

		this._reviewPanelVisible = ctxReviewPanelVisible.bindTo(contextKeyService);
198
		this._commentingRangeDecorator = new CommentingRangeDecorator();
199

200 201 202 203 204 205 206 207 208 209
		this.globalToDispose.push(this.commentService.onDidDeleteDataProvider(e => {
			// Remove new comment widget and glyph, refresh comments
			if (this._newCommentWidget) {
				this._newCommentWidget.dispose();
				this._newCommentWidget = null;
			}

			this.getComments();
		}));

210
		this.globalToDispose.push(this.commentService.onDidSetResourceCommentInfos(e => {
211 212
			const editorURI = this.editor && this.editor.getModel() && this.editor.getModel().uri;
			if (editorURI && editorURI.toString() === e.resource.toString()) {
213
				this.setComments(e.commentInfos.filter(commentInfo => commentInfo !== null));
214
			}
P
Peng Lyu 已提交
215 216
		}));

217
		this.globalToDispose.push(this.commentService.onDidSetDataProvider(_ => this.getComments()));
218

P
Peng Lyu 已提交
219
		this.globalToDispose.push(this.editor.onDidChangeModel(() => this.onModelChanged()));
P
Peng Lyu 已提交
220
		this.codeEditorService.registerDecorationType(COMMENTEDITOR_DECORATION_KEY, {});
P
Peng Lyu 已提交
221 222
	}

223 224 225 226 227 228 229 230 231 232
	private getComments(): void {
		const editorURI = this.editor && this.editor.getModel() && this.editor.getModel().uri;

		if (editorURI) {
			this.commentService.getComments(editorURI).then(commentInfos => {
				this.setComments(commentInfos.filter(commentInfo => commentInfo !== null));
			}, error => console.log(error));
		}
	}

P
Peng Lyu 已提交
233 234 235 236
	public static get(editor: ICodeEditor): ReviewController {
		return editor.getContribution<ReviewController>(ID);
	}

P
Peng Lyu 已提交
237
	public revealCommentThread(threadId: string, commentId?: string): void {
R
Rachel Macfarlane 已提交
238
		const commentThreadWidget = this._commentWidgets.filter(widget => widget.commentThread.threadId === threadId);
239
		if (commentThreadWidget.length === 1) {
P
Peng Lyu 已提交
240
			commentThreadWidget[0].reveal(commentId);
241 242 243
		}
	}

P
Peng Lyu 已提交
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
	public nextCommentThread(): void {
		if (!this._commentWidgets.length) {
			return;
		}

		const after = this.editor.getSelection().getEndPosition();
		const sortedWidgets = this._commentWidgets.sort((a, b) => {
			if (a.commentThread.range.startLineNumber < b.commentThread.range.startLineNumber) {
				return -1;
			}

			if (a.commentThread.range.startLineNumber > b.commentThread.range.startLineNumber) {
				return 1;
			}

			if (a.commentThread.range.startColumn < b.commentThread.range.startColumn) {
				return -1;
			}

			if (a.commentThread.range.startColumn > b.commentThread.range.startColumn) {
				return 1;
			}

			return 0;
		});

		let idx = findFirstInSorted(sortedWidgets, widget => {
			if (widget.commentThread.range.startLineNumber > after.lineNumber) {
				return true;
			}

			if (widget.commentThread.range.startLineNumber < after.lineNumber) {
				return false;
			}

			if (widget.commentThread.range.startColumn > after.column) {
				return true;
			}
			return false;
		});

		if (idx === this._commentWidgets.length) {
			this._commentWidgets[0].reveal();
			this.editor.setSelection(this._commentWidgets[0].commentThread.range);
		} else {
			sortedWidgets[idx].reveal();
			this.editor.setSelection(sortedWidgets[idx].commentThread.range);
		}
	}

P
Peng Lyu 已提交
294 295 296
	getId(): string {
		return ID;
	}
297

P
Peng Lyu 已提交
298 299 300 301
	dispose(): void {
		this.globalToDispose = dispose(this.globalToDispose);
		this.localToDispose = dispose(this.localToDispose);

302 303
		this._commentWidgets.forEach(widget => widget.dispose());

R
Rachel Macfarlane 已提交
304 305 306
		if (this._newCommentWidget) {
			this._newCommentWidget.dispose();
			this._newCommentWidget = null;
P
Peng Lyu 已提交
307 308 309 310 311 312
		}
		this.editor = null;
	}

	public onModelChanged(): void {
		this.localToDispose = dispose(this.localToDispose);
R
Rachel Macfarlane 已提交
313
		if (this._newCommentWidget) {
B
Benjamin Pasero 已提交
314
			// todo@peng store view state.
R
Rachel Macfarlane 已提交
315 316
			this._newCommentWidget.dispose();
			this._newCommentWidget = null;
P
Peng Lyu 已提交
317
		}
318

R
Rachel Macfarlane 已提交
319
		this._commentWidgets.forEach(zone => {
320 321
			zone.dispose();
		});
R
Rachel Macfarlane 已提交
322
		this._commentWidgets = [];
323

324 325
		this.localToDispose.push(this.editor.onMouseDown(e => this.onEditorMouseDown(e)));
		this.localToDispose.push(this.editor.onMouseUp(e => this.onEditorMouseUp(e)));
326 327
		this.localToDispose.push(this.editor.onDidChangeModelContent(() => {
		}));
P
Peng Lyu 已提交
328 329 330 331 332
		this.localToDispose.push(this.commentService.onDidUpdateCommentThreads(e => {
			const editorURI = this.editor && this.editor.getModel() && this.editor.getModel().uri;
			if (!editorURI) {
				return;
			}
333 334 335 336 337

			if (!this._commentInfos.some(info => info.owner === e.owner)) {
				return;
			}

P
Peng Lyu 已提交
338 339 340 341 342
			let added = e.added.filter(thread => thread.resource.toString() === editorURI.toString());
			let removed = e.removed.filter(thread => thread.resource.toString() === editorURI.toString());
			let changed = e.changed.filter(thread => thread.resource.toString() === editorURI.toString());

			removed.forEach(thread => {
R
Rachel Macfarlane 已提交
343
				let matchedZones = this._commentWidgets.filter(zoneWidget => zoneWidget.owner === e.owner && zoneWidget.commentThread.threadId === thread.threadId);
P
Peng Lyu 已提交
344 345
				if (matchedZones.length) {
					let matchedZone = matchedZones[0];
R
Rachel Macfarlane 已提交
346 347
					let index = this._commentWidgets.indexOf(matchedZone);
					this._commentWidgets.splice(index, 1);
P
Peng Lyu 已提交
348 349 350 351
				}
			});

			changed.forEach(thread => {
R
Rachel Macfarlane 已提交
352
				let matchedZones = this._commentWidgets.filter(zoneWidget => zoneWidget.owner === e.owner && zoneWidget.commentThread.threadId === thread.threadId);
P
Peng Lyu 已提交
353 354 355 356 357 358
				if (matchedZones.length) {
					let matchedZone = matchedZones[0];
					matchedZone.update(thread);
				}
			});
			added.forEach(thread => {
359
				let zoneWidget = new ReviewZoneWidget(this.instantiationService, this.modeService, this.modelService, this.themeService, this.commentService, this.openerService, this.editor, e.owner, thread, {});
360
				zoneWidget.display(thread.range.startLineNumber, this._commentingRangeDecorator.commentsOptions);
R
Rachel Macfarlane 已提交
361
				this._commentWidgets.push(zoneWidget);
362
				this._commentInfos.filter(info => info.owner === e.owner)[0].threads.push(thread);
P
Peng Lyu 已提交
363 364
			});
		}));
P
Peng Lyu 已提交
365 366
	}

367
	private addComment(lineNumber: number) {
368 369 370 371 372
		if (this._newCommentWidget !== null) {
			this.notificationService.warn(`Please submit the comment at line ${this._newCommentWidget.position.lineNumber} before creating a new one.`);
			return;
		}

P
Peng Lyu 已提交
373
		let newCommentInfo = this._commentingRangeDecorator.getMatchedCommentAction(lineNumber);
374 375
		if (!newCommentInfo) {
			return;
P
Peng Lyu 已提交
376
		}
377 378 379

		// add new comment
		this._reviewPanelVisible.set(true);
380
		const { replyCommand, ownerId } = newCommentInfo;
381
		this._newCommentWidget = new ReviewZoneWidget(this.instantiationService, this.modeService, this.modelService, this.themeService, this.commentService, this.openerService, this.editor, ownerId, {
382 383 384 385 386 387 388 389 390
			threadId: null,
			resource: null,
			comments: [],
			range: {
				startLineNumber: lineNumber,
				startColumn: 0,
				endLineNumber: lineNumber,
				endColumn: 0
			},
391
			reply: replyCommand,
392
			collapsibleState: CommentThreadCollapsibleState.Expanded,
393
		}, {});
394

395
		this.localToDispose.push(this._newCommentWidget.onDidClose(e => {
R
Rachel Macfarlane 已提交
396
			this._newCommentWidget = null;
397 398 399 400 401 402 403 404 405
		}));

		this.localToDispose.push(this._newCommentWidget.onDidCreateThread(commentWidget => {
			const thread = commentWidget.commentThread;
			this._commentWidgets.push(commentWidget);
			this._commentInfos.filter(info => info.owner === commentWidget.owner)[0].threads.push(thread);
			this._newCommentWidget = null;
		}));

406
		this._newCommentWidget.display(lineNumber, this._commentingRangeDecorator.commentsOptions);
P
Peng Lyu 已提交
407 408
	}

409 410 411 412 413 414
	private onEditorMouseDown(e: IEditorMouseEvent): void {
		this.mouseDownInfo = null;

		const range = e.target.range;

		if (!range) {
415 416 417
			return;
		}

418 419 420 421 422 423 424 425 426 427 428
		if (!e.event.leftButton) {
			return;
		}

		if (e.target.type !== MouseTargetType.GUTTER_LINE_DECORATIONS) {
			return;
		}

		const data = e.target.detail as IMarginData;
		const gutterOffsetX = data.offsetX - data.glyphMarginWidth - data.lineNumbersWidth - data.glyphMarginLeft;

429
		// don't collide with folding and git decorations
430
		if (gutterOffsetX > 14) {
431 432 433 434 435 436 437 438 439 440
			return;
		}

		this.mouseDownInfo = { lineNumber: range.startLineNumber };
	}

	private onEditorMouseUp(e: IEditorMouseEvent): void {
		if (!this.mouseDownInfo) {
			return;
		}
441

442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
		const { lineNumber } = this.mouseDownInfo;
		this.mouseDownInfo = null;

		const range = e.target.range;

		if (!range || range.startLineNumber !== lineNumber) {
			return;
		}

		if (e.target.type !== MouseTargetType.GUTTER_LINE_DECORATIONS) {
			return;
		}

		if (!e.target.element) {
			return;
		}

459
		if (e.target.element.className.indexOf('comment-diff-added') >= 0) {
R
Rachel Macfarlane 已提交
460
			const lineNumber = e.target.position.lineNumber;
P
Peng Lyu 已提交
461
			this.addComment(lineNumber);
462
		}
P
Peng Lyu 已提交
463 464
	}

465 466
	setComments(commentInfos: modes.CommentInfo[]): void {
		this._commentInfos = commentInfos;
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489
		let lineDecorationsWidth: number = this.editor.getConfiguration().layoutInfo.decorationsWidth;

		if (this._commentInfos.some(info => Boolean(info.commentingRanges && info.commentingRanges.length))) {
			if (!this._commentingRangeSpaceReserved) {
				this._commentingRangeSpaceReserved = true;
				let extraEditorClassName = [];
				if (this.editor.getRawConfiguration().extraEditorClassName) {
					extraEditorClassName = this.editor.getRawConfiguration().extraEditorClassName.split(' ');
				}

				if (this.editor.getConfiguration().contribInfo.folding) {
					lineDecorationsWidth -= 16;
				}
				lineDecorationsWidth += 9;
				extraEditorClassName.push('inline-comment');
				this.editor.updateOptions({
					extraEditorClassName: extraEditorClassName.join(' '),
					lineDecorationsWidth: lineDecorationsWidth
				});
				this.editor.layout();
			}
		}

490
		// this._hasSetComments = true;
491

492
		// create viewzones
R
Rachel Macfarlane 已提交
493
		this._commentWidgets.forEach(zone => {
494 495 496
			zone.dispose();
		});

497 498
		this._commentWidgets = [];

499 500
		this._commentInfos.forEach(info => {
			info.threads.forEach(thread => {
501
				let zoneWidget = new ReviewZoneWidget(this.instantiationService, this.modeService, this.modelService, this.themeService, this.commentService, this.openerService, this.editor, info.owner, thread, {});
502
				zoneWidget.display(thread.range.startLineNumber, this._commentingRangeDecorator.commentsOptions);
R
Rachel Macfarlane 已提交
503
				this._commentWidgets.push(zoneWidget);
504 505
			});
		});
506 507

		const commentingRanges = [];
508 509 510
		this._commentInfos.forEach(info => {
			commentingRanges.push(...info.commentingRanges);
		});
P
Peng Lyu 已提交
511
		this._commentingRangeDecorator.update(this.editor, this._commentInfos);
M
Matt Bierner 已提交
512 513
	}

P
Peng Lyu 已提交
514 515 516
	public closeWidget(): void {
		this._reviewPanelVisible.reset();

R
Rachel Macfarlane 已提交
517 518 519
		if (this._newCommentWidget) {
			this._newCommentWidget.dispose();
			this._newCommentWidget = null;
P
Peng Lyu 已提交
520 521
		}

R
Rachel Macfarlane 已提交
522
		if (this._commentWidgets) {
523
			this._commentWidgets.forEach(widget => widget.hide());
524 525
		}

P
Peng Lyu 已提交
526
		this.editor.focus();
527
		this.editor.revealRangeInCenter(this.editor.getSelection());
P
Peng Lyu 已提交
528 529 530
	}
}

P
Peng Lyu 已提交
531
export class NextCommentThreadAction extends EditorAction {
P
Peng Lyu 已提交
532

P
Peng Lyu 已提交
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551
	constructor() {
		super({
			id: 'editor.action.nextCommentThreadAction',
			label: nls.localize('nextCommentThreadAction', "Go to Next Comment Thread"),
			alias: 'Go to Next Comment Thread',
			precondition: null,
		});
	}

	public run(accessor: ServicesAccessor, editor: ICodeEditor): void {
		let controller = ReviewController.get(editor);
		if (controller) {
			controller.nextCommentThread();
		}
	}
}

registerEditorContribution(ReviewController);
registerEditorAction(NextCommentThreadAction);
P
Peng Lyu 已提交
552 553 554

KeybindingsRegistry.registerCommandAndKeybindingRule({
	id: 'closeReviewPanel',
555
	weight: KeybindingWeight.EditorContrib,
P
Peng Lyu 已提交
556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582
	primary: KeyCode.Escape,
	secondary: [KeyMod.Shift | KeyCode.Escape],
	when: ctxReviewPanelVisible,
	handler: closeReviewPanel
});

export function getOuterEditor(accessor: ServicesAccessor): ICodeEditor {
	let editor = accessor.get(ICodeEditorService).getFocusedCodeEditor();
	if (editor instanceof EmbeddedCodeEditorWidget) {
		return editor.getParentEditor();
	}
	return editor;
}

function closeReviewPanel(accessor: ServicesAccessor, args: any) {
	var outerEditor = getOuterEditor(accessor);
	if (!outerEditor) {
		return;
	}

	let controller = ReviewController.get(outerEditor);

	if (!controller) {
		return;
	}

	controller.closeWidget();
583 584 585 586
}


registerThemingParticipant((theme, collector) => {
P
Peng Lyu 已提交
587
	let peekViewBackground = theme.getColor(peekViewResultsBackground);
P
Peng Lyu 已提交
588
	if (peekViewBackground) {
589 590 591
		collector.addRule(
			`.monaco-editor .review-widget,` +
			`.monaco-editor .review-widget {` +
P
Peng Lyu 已提交
592
			`	background-color: ${peekViewBackground};` +
593 594
			`}`);
	}
P
Peng Lyu 已提交
595

596
	let monacoEditorBackground = theme.getColor(peekViewTitleBackground);
P
Peng Lyu 已提交
597 598
	if (monacoEditorBackground) {
		collector.addRule(
P
Peng Lyu 已提交
599 600
			`.monaco-editor .review-widget .body .comment-form .review-thread-reply-button {` +
			`	background-color: ${monacoEditorBackground}` +
P
Peng Lyu 已提交
601 602 603 604 605 606 607
			`}`
		);
	}

	let monacoEditorForeground = theme.getColor(editorForeground);
	if (monacoEditorForeground) {
		collector.addRule(
P
Peng Lyu 已提交
608
			`.monaco-editor .review-widget .body .monaco-editor {` +
P
Peng Lyu 已提交
609
			`	color: ${monacoEditorForeground}` +
P
Peng Lyu 已提交
610 611 612
			`}` +
			`.monaco-editor .review-widget .body .comment-form .review-thread-reply-button {` +
			`	color: ${monacoEditorForeground}` +
P
Peng Lyu 已提交
613 614 615
			`}`
		);
	}
P
Peng Lyu 已提交
616 617 618 619 620 621 622 623 624 625 626 627 628 629

	let selectionBackground = theme.getColor(peekViewResultsSelectionBackground);

	if (selectionBackground) {
		collector.addRule(
			`@keyframes monaco-review-widget-focus {` +
			`	0% { background: ${selectionBackground}; }` +
			`	100% { background: transparent; }` +
			`}` +
			`.monaco-editor .review-widget .body .review-comment.focus {` +
			`	animation: monaco-review-widget-focus 3s ease 0s;` +
			`}`
		);
	}
630 631 632 633 634 635 636 637 638 639

	const commentingRangeForeground = theme.getColor(overviewRulerCommentingRangeForeground);
	if (commentingRangeForeground) {
		collector.addRule(`
			.monaco-editor .comment-diff-added {
				border-left: 3px solid ${commentingRangeForeground};
			}
			.monaco-editor .comment-diff-added:before {
				background: ${commentingRangeForeground};
			}
640 641 642 643 644 645
			.monaco-editor .comment-thread {
				border-left: 3px solid ${commentingRangeForeground};
			}
			.monaco-editor .comment-thread:before {
				background: ${commentingRangeForeground};
			}
646 647
		`);
	}
648
});