Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make max comment area height depend on editor height #194308

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/vs/workbench/contrib/comments/browser/commentNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { ILanguageService } from 'vs/editor/common/languages/language';
import { MarkdownRenderer } from 'vs/editor/contrib/markdownRenderer/browser/markdownRenderer';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ICommentService } from 'vs/workbench/contrib/comments/browser/commentService';
import { STARTING_EDITOR_HEIGHT, SimpleCommentEditor, calculateEditorHeight } from 'vs/workbench/contrib/comments/browser/simpleCommentEditor';
import { LayoutableEditor, STARTING_EDITOR_HEIGHT, SimpleCommentEditor, calculateEditorHeight } from 'vs/workbench/contrib/comments/browser/simpleCommentEditor';
import { Selection } from 'vs/editor/common/core/selection';
import { Emitter, Event } from 'vs/base/common/event';
import { INotificationService } from 'vs/platform/notification/common/notification';
Expand Down Expand Up @@ -98,6 +98,7 @@ export class CommentNode<T extends IRange | ICellRange> extends Disposable {
public isEditing: boolean = false;

constructor(
private readonly parentEditor: LayoutableEditor,
private commentThread: languages.CommentThread<T>,
public comment: languages.Comment,
private pendingEdit: string | undefined,
Expand Down Expand Up @@ -536,7 +537,7 @@ export class CommentNode<T extends IRange | ICellRange> extends Disposable {

private calculateEditorHeight(): boolean {
if (this._commentEditor) {
const newEditorHeight = calculateEditorHeight(this._commentEditor, this._editorHeight);
const newEditorHeight = calculateEditorHeight(this.parentEditor, this._commentEditor, this._editorHeight);
if (newEditorHeight !== this._editorHeight) {
this._editorHeight = newEditorHeight;
return true;
Expand Down
5 changes: 3 additions & 2 deletions src/vs/workbench/contrib/comments/browser/commentReply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { ICommentService } from 'vs/workbench/contrib/comments/browser/commentSe
import { CommentContextKeys } from 'vs/workbench/contrib/comments/common/commentContextKeys';
import { ICommentThreadWidget } from 'vs/workbench/contrib/comments/common/commentThreadWidget';
import { ICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange';
import { STARTING_EDITOR_HEIGHT, SimpleCommentEditor, calculateEditorHeight } from './simpleCommentEditor';
import { LayoutableEditor, STARTING_EDITOR_HEIGHT, SimpleCommentEditor, calculateEditorHeight } from './simpleCommentEditor';

const COMMENT_SCHEME = 'comment';
let INMEM_MODEL_ID = 0;
Expand All @@ -50,6 +50,7 @@ export class CommentReply<T extends IRange | ICellRange> extends Disposable {
constructor(
readonly owner: string,
container: HTMLElement,
private readonly _parentEditor: LayoutableEditor,
private _commentThread: languages.CommentThread<T>,
private _scopedInstatiationService: IInstantiationService,
private _contextKeyService: IContextKeyService,
Expand Down Expand Up @@ -117,7 +118,7 @@ export class CommentReply<T extends IRange | ICellRange> extends Disposable {
}

private calculateEditorHeight(): boolean {
const newEditorHeight = calculateEditorHeight(this.commentEditor, this._editorHeight);
const newEditorHeight = calculateEditorHeight(this._parentEditor, this.commentEditor, this._editorHeight);
if (newEditorHeight !== this._editorHeight) {
this._editorHeight = newEditorHeight;
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { IOpenerService } from 'vs/platform/opener/common/opener';
import { ILanguageService } from 'vs/editor/common/languages/language';
import { ICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange';
import { IRange } from 'vs/editor/common/core/range';
import { LayoutableEditor } from 'vs/workbench/contrib/comments/browser/simpleCommentEditor';

export class CommentThreadBody<T extends IRange | ICellRange = IRange> extends Disposable {
private _commentsElement!: HTMLElement;
Expand All @@ -42,6 +43,7 @@ export class CommentThreadBody<T extends IRange | ICellRange = IRange> extends D


constructor(
private readonly _parentEditor: LayoutableEditor,
readonly owner: string,
readonly parentResourceUri: URI,
readonly container: HTMLElement,
Expand Down Expand Up @@ -254,6 +256,7 @@ export class CommentThreadBody<T extends IRange | ICellRange = IRange> extends D

private createNewCommentNode(comment: languages.Comment): CommentNode<T> {
const newCommentNode = this._scopedInstatiationService.createInstance(CommentNode,
this._parentEditor,
this._commentThread,
comment,
this._pendingEdits ? this._pendingEdits[comment.uniqueIdInThread!] : undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { localize } from 'vs/nls';
import { AccessibilityVerbositySettingId } from 'vs/workbench/contrib/accessibility/browser/accessibilityConfiguration';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { AccessibilityCommandId } from 'vs/workbench/contrib/accessibility/common/accessibilityCommands';
import { LayoutableEditor } from 'vs/workbench/contrib/comments/browser/simpleCommentEditor';

export const COMMENTEDITOR_DECORATION_KEY = 'commenteditordecoration';

Expand All @@ -60,6 +61,7 @@ export class CommentThreadWidget<T extends IRange | ICellRange = IRange> extends
}
constructor(
readonly container: HTMLElement,
readonly _parentEditor: LayoutableEditor,
private _owner: string,
private _parentResourceUri: URI,
private _contextKeyService: IContextKeyService,
Expand Down Expand Up @@ -126,6 +128,7 @@ export class CommentThreadWidget<T extends IRange | ICellRange = IRange> extends
}));
this._body = this._scopedInstantiationService.createInstance(
CommentThreadBody,
this._parentEditor,
this._owner,
this._parentResourceUri,
bodyElement,
Expand Down Expand Up @@ -286,6 +289,7 @@ export class CommentThreadWidget<T extends IRange | ICellRange = IRange> extends
CommentReply,
this._owner,
this._body.container,
this._parentEditor,
this._commentThread,
this._scopedInstantiationService,
this._contextKeyService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
this._commentThreadWidget = this._scopedInstantiationService.createInstance(
CommentThreadWidget,
container,
this.editor,
this._owner,
this.editor.getModel()!.uri,
this._contextKeyService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export const ctxCommentEditorFocused = new RawContextKey<boolean>('commentEditor
export const STARTING_EDITOR_HEIGHT = 5 * 18;
export const MAX_EDITOR_HEIGHT = 25 * 18;

export interface LayoutableEditor {
getLayoutInfo(): { height: number };
}

export class SimpleCommentEditor extends CodeEditorWidget {
private _parentThread: ICommentThreadWidget;
private _commentEditorFocused: IContextKey<boolean>;
Expand Down Expand Up @@ -112,14 +116,15 @@ export class SimpleCommentEditor extends CodeEditorWidget {
}
}

export function calculateEditorHeight(editor: ICodeEditor, currentHeight: number): number {
export function calculateEditorHeight(parentEditor: LayoutableEditor, editor: ICodeEditor, currentHeight: number): number {
const layoutInfo = editor.getLayoutInfo();
const lineHeight = editor.getOption(EditorOption.lineHeight);
const contentHeight = (editor.getModel()?.getLineCount()! * lineHeight) ?? editor.getContentHeight(); // Can't just call getContentHeight() because it returns an incorrect, large, value when the editor is first created.
if ((contentHeight > layoutInfo.height) ||
(contentHeight < layoutInfo.height && currentHeight > STARTING_EDITOR_HEIGHT)) {
const linesToAdd = Math.ceil((contentHeight - layoutInfo.height) / lineHeight);
const newEditorHeight = Math.min(MAX_EDITOR_HEIGHT, layoutInfo.height + (lineHeight * linesToAdd));
const maxCommentEditorHeight = Math.max(Math.min(MAX_EDITOR_HEIGHT, parentEditor.getLayoutInfo().height - 90), STARTING_EDITOR_HEIGHT);
const newEditorHeight = Math.min(maxCommentEditorHeight, layoutInfo.height + (lineHeight * linesToAdd));
return newEditorHeight;
}
return currentHeight;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export class CellComments extends CellContentPart {
this._commentThreadWidget = this.instantiationService.createInstance(
CommentThreadWidget,
this.container,
this.notebookEditor,
owner,
this.notebookEditor.textModel!.uri,
this.contextKeyService,
Expand Down