Merge from vscode de81ccf04849309f843db21130c806a5783678f7 (#4738)

This commit is contained in:
Anthony Dresser
2019-03-28 13:06:16 -07:00
committed by GitHub
parent cc2951265e
commit e6785ffe95
77 changed files with 562 additions and 835 deletions

View File

@@ -199,27 +199,29 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
this._actionbarWidget = new ActionBar(actionsContainer, {});
this._disposables.push(this._actionbarWidget);
this._collapseAction = new Action('review.expand', nls.localize('label.collapse', "Collapse"), COLLAPSE_ACTION_CLASS, true, () => {
if (this._commentThread.comments.length === 0) {
if ((this._commentThread as modes.CommentThread2).commentThreadHandle === undefined) {
this.dispose();
return Promise.resolve();
} else {
const deleteCommand = (this._commentThread as modes.CommentThread2).deleteCommand;
if (deleteCommand) {
return this.commandService.executeCommand(deleteCommand.id, ...(deleteCommand.arguments || []));
}
}
}
this._isCollapsed = true;
this.hide();
return Promise.resolve();
});
this._collapseAction = new Action('review.expand', nls.localize('label.collapse', "Collapse"), COLLAPSE_ACTION_CLASS, true, () => this.collapse());
this._actionbarWidget.push(this._collapseAction, { label: false, icon: true });
}
public collapse(): Promise<void> {
if (this._commentThread.comments.length === 0) {
if ((this._commentThread as modes.CommentThread2).commentThreadHandle === undefined) {
this.dispose();
return Promise.resolve();
} else {
const deleteCommand = (this._commentThread as modes.CommentThread2).deleteCommand;
if (deleteCommand) {
return this.commandService.executeCommand(deleteCommand.id, ...(deleteCommand.arguments || []));
}
}
}
this._isCollapsed = true;
this.hide();
return Promise.resolve();
}
public getGlyphPosition(): number {
if (this._commentGlyph) {
return this._commentGlyph.getPosition().position!.lineNumber;
@@ -291,8 +293,10 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
// Move comment glyph widget and show position if the line has changed.
const lineNumber = this._commentThread.range.startLineNumber;
let shouldMoveWidget = false;
if (this._commentGlyph) {
if (this._commentGlyph.getPosition().position!.lineNumber !== lineNumber) {
shouldMoveWidget = true;
this._commentGlyph.setLineNumber(lineNumber);
}
}
@@ -301,7 +305,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
this.createReplyButton();
}
if (!this._isCollapsed) {
if (shouldMoveWidget && !this._isCollapsed) {
this.show({ lineNumber, column: 1 }, 2);
}
}
@@ -319,11 +323,11 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
}
protected _onWidth(widthInPixel: number): void {
this._commentEditor.layout({ height: (this._commentEditor.hasWidgetFocus() ? 5 : 1) * 18, width: widthInPixel - 54 /* margin 20px * 10 + scrollbar 14px*/ });
this._commentEditor.layout({ height: 5 * 18, width: widthInPixel - 54 /* margin 20px * 10 + scrollbar 14px*/ });
}
protected _doLayout(heightInPixel: number, widthInPixel: number): void {
this._commentEditor.layout({ height: (this._commentEditor.hasWidgetFocus() ? 5 : 1) * 18, width: widthInPixel - 54 /* margin 20px * 10 + scrollbar 14px*/ });
this._commentEditor.layout({ height: 5 * 18, width: widthInPixel - 54 /* margin 20px * 10 + scrollbar 14px*/ });
}
display(lineNumber: number) {
@@ -451,13 +455,15 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
this._disposables.push((this._commentThread as modes.CommentThread2).onDidChangeRange(range => {
// Move comment glyph widget and show position if the line has changed.
const lineNumber = this._commentThread.range.startLineNumber;
let shouldMoveWidget = false;
if (this._commentGlyph) {
if (this._commentGlyph.getPosition().position!.lineNumber !== lineNumber) {
shouldMoveWidget = true;
this._commentGlyph.setLineNumber(lineNumber);
}
}
if (!this._isCollapsed) {
if (shouldMoveWidget && !this._isCollapsed) {
this.show({ lineNumber, column: 1 }, 2);
}
}));
@@ -997,6 +1003,8 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
hide() {
this._isCollapsed = true;
// Focus the container so that the comment editor will be blurred before it is hidden
this.editor.focus();
super.hide();
}

View File

@@ -16,7 +16,6 @@ import { IEditorContribution, IModelChangedEvent } from 'vs/editor/common/editor
import { IRange, Range } from 'vs/editor/common/core/range';
import * as modes from 'vs/editor/common/modes';
import { peekViewResultsBackground, peekViewResultsSelectionBackground, peekViewTitleBackground } from 'vs/editor/contrib/referenceSearch/referencesWidget';
import { IContextKey, IContextKeyService, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
import { ServicesAccessor, IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { editorForeground } from 'vs/platform/theme/common/colorRegistry';
@@ -36,8 +35,6 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic
import { ctxCommentEditorFocused, SimpleCommentEditor } from 'vs/workbench/contrib/comments/browser/simpleCommentEditor';
import { onUnexpectedError } from 'vs/base/common/errors';
export const ctxCommentThreadVisible = new RawContextKey<boolean>('commentThreadVisible', false);
export const ID = 'editor.contrib.review';
export class ReviewViewZone implements IViewZone {
@@ -161,7 +158,6 @@ export class ReviewController implements IEditorContribution {
private editor: ICodeEditor;
private _newCommentWidget?: ReviewZoneWidget;
private _commentWidgets: ReviewZoneWidget[];
private _commentThreadVisible: IContextKey<boolean>;
private _commentInfos: ICommentInfo[];
private _commentingRangeDecorator: CommentingRangeDecorator;
private mouseDownInfo: { lineNumber: number } | null = null;
@@ -176,7 +172,6 @@ export class ReviewController implements IEditorContribution {
constructor(
editor: ICodeEditor,
@IContextKeyService readonly contextKeyService: IContextKeyService,
@ICommentService private readonly commentService: ICommentService,
@ICommandService private readonly _commandService: ICommandService,
@INotificationService private readonly notificationService: INotificationService,
@@ -193,7 +188,6 @@ export class ReviewController implements IEditorContribution {
this._pendingNewCommentCache = {};
this._computePromise = null;
this._commentThreadVisible = ctxCommentThreadVisible.bindTo(contextKeyService);
this._commentingRangeDecorator = new CommentingRangeDecorator();
this.globalToDispose.push(this.commentService.onDidDeleteDataProvider(ownerId => {
@@ -458,7 +452,6 @@ export class ReviewController implements IEditorContribution {
}
// add new comment
this._commentThreadVisible.set(true);
this._newCommentWidget = this.instantiationService.createInstance(ReviewZoneWidget, this.editor, ownerId, {
extensionId: extensionId,
threadId: null,
@@ -687,8 +680,6 @@ export class ReviewController implements IEditorContribution {
}
public closeWidget(): void {
this._commentThreadVisible.reset();
if (this._newCommentWidget) {
this._newCommentWidget.dispose();
this._newCommentWidget = undefined;
@@ -783,12 +774,17 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'closeReviewPanel',
id: 'workbench.action.hideComment',
weight: KeybindingWeight.EditorContrib,
primary: KeyCode.Escape,
secondary: [KeyMod.Shift | KeyCode.Escape],
when: ctxCommentThreadVisible,
handler: closeReviewPanel
when: ctxCommentEditorFocused,
handler: (accessor, args) => {
const activeCodeEditor = accessor.get(ICodeEditorService).getFocusedCodeEditor();
if (activeCodeEditor instanceof SimpleCommentEditor) {
activeCodeEditor.getParentThread().collapse();
}
}
});
export function getActiveEditor(accessor: ServicesAccessor): IActiveCodeEditor | null {
@@ -809,21 +805,6 @@ export function getActiveEditor(accessor: ServicesAccessor): IActiveCodeEditor |
return activeTextEditorWidget;
}
function closeReviewPanel(accessor: ServicesAccessor, args: any) {
const outerEditor = getActiveEditor(accessor);
if (!outerEditor) {
return;
}
const controller = ReviewController.get(outerEditor);
if (!controller) {
return;
}
controller.closeWidget();
}
registerThemingParticipant((theme, collector) => {
const peekViewBackground = theme.getColor(peekViewResultsBackground);
if (peekViewBackground) {

View File

@@ -5,4 +5,5 @@
export interface ICommentThreadWidget {
submitComment: () => Promise<void>;
}
collapse: () => void;
}