提交 de81ccf0 编写于 作者: R Rachel Macfarlane

Fix #71155, pressing escape while comment is focused should hide it

上级 5c0fc719
......@@ -199,25 +199,27 @@ 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._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();
});
this._actionbarWidget.push(this._collapseAction, { label: false, icon: true });
this._isCollapsed = true;
this.hide();
return Promise.resolve();
}
public getGlyphPosition(): number {
......@@ -1001,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();
}
......
......@@ -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) {
......
......@@ -5,4 +5,5 @@
export interface ICommentThreadWidget {
submitComment: () => Promise<void>;
collapse: () => void;
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册