Skip to content

Commit eef5ae1

Browse files
authored
Make max comment area height depend on editor height (microsoft#194308)
Fixes microsoft#194133
1 parent 7b0ab1f commit eef5ae1

File tree

7 files changed

+22
-6
lines changed

7 files changed

+22
-6
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { ILanguageService } from 'vs/editor/common/languages/language';
1616
import { MarkdownRenderer } from 'vs/editor/contrib/markdownRenderer/browser/markdownRenderer';
1717
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
1818
import { ICommentService } from 'vs/workbench/contrib/comments/browser/commentService';
19-
import { STARTING_EDITOR_HEIGHT, SimpleCommentEditor, calculateEditorHeight } from 'vs/workbench/contrib/comments/browser/simpleCommentEditor';
19+
import { LayoutableEditor, STARTING_EDITOR_HEIGHT, SimpleCommentEditor, calculateEditorHeight } from 'vs/workbench/contrib/comments/browser/simpleCommentEditor';
2020
import { Selection } from 'vs/editor/common/core/selection';
2121
import { Emitter, Event } from 'vs/base/common/event';
2222
import { INotificationService } from 'vs/platform/notification/common/notification';
@@ -98,6 +98,7 @@ export class CommentNode<T extends IRange | ICellRange> extends Disposable {
9898
public isEditing: boolean = false;
9999

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

537538
private calculateEditorHeight(): boolean {
538539
if (this._commentEditor) {
539-
const newEditorHeight = calculateEditorHeight(this._commentEditor, this._editorHeight);
540+
const newEditorHeight = calculateEditorHeight(this.parentEditor, this._commentEditor, this._editorHeight);
540541
if (newEditorHeight !== this._editorHeight) {
541542
this._editorHeight = newEditorHeight;
542543
return true;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { ICommentService } from 'vs/workbench/contrib/comments/browser/commentSe
2828
import { CommentContextKeys } from 'vs/workbench/contrib/comments/common/commentContextKeys';
2929
import { ICommentThreadWidget } from 'vs/workbench/contrib/comments/common/commentThreadWidget';
3030
import { ICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange';
31-
import { STARTING_EDITOR_HEIGHT, SimpleCommentEditor, calculateEditorHeight } from './simpleCommentEditor';
31+
import { LayoutableEditor, STARTING_EDITOR_HEIGHT, SimpleCommentEditor, calculateEditorHeight } from './simpleCommentEditor';
3232

3333
const COMMENT_SCHEME = 'comment';
3434
let INMEM_MODEL_ID = 0;
@@ -50,6 +50,7 @@ export class CommentReply<T extends IRange | ICellRange> extends Disposable {
5050
constructor(
5151
readonly owner: string,
5252
container: HTMLElement,
53+
private readonly _parentEditor: LayoutableEditor,
5354
private _commentThread: languages.CommentThread<T>,
5455
private _scopedInstatiationService: IInstantiationService,
5556
private _contextKeyService: IContextKeyService,
@@ -117,7 +118,7 @@ export class CommentReply<T extends IRange | ICellRange> extends Disposable {
117118
}
118119

119120
private calculateEditorHeight(): boolean {
120-
const newEditorHeight = calculateEditorHeight(this.commentEditor, this._editorHeight);
121+
const newEditorHeight = calculateEditorHeight(this._parentEditor, this.commentEditor, this._editorHeight);
121122
if (newEditorHeight !== this._editorHeight) {
122123
this._editorHeight = newEditorHeight;
123124
return true;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { IOpenerService } from 'vs/platform/opener/common/opener';
2020
import { ILanguageService } from 'vs/editor/common/languages/language';
2121
import { ICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange';
2222
import { IRange } from 'vs/editor/common/core/range';
23+
import { LayoutableEditor } from 'vs/workbench/contrib/comments/browser/simpleCommentEditor';
2324

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

4344

4445
constructor(
46+
private readonly _parentEditor: LayoutableEditor,
4547
readonly owner: string,
4648
readonly parentResourceUri: URI,
4749
readonly container: HTMLElement,
@@ -254,6 +256,7 @@ export class CommentThreadBody<T extends IRange | ICellRange = IRange> extends D
254256

255257
private createNewCommentNode(comment: languages.Comment): CommentNode<T> {
256258
const newCommentNode = this._scopedInstatiationService.createInstance(CommentNode,
259+
this._parentEditor,
257260
this._commentThread,
258261
comment,
259262
this._pendingEdits ? this._pendingEdits[comment.uniqueIdInThread!] : undefined,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { localize } from 'vs/nls';
3535
import { AccessibilityVerbositySettingId } from 'vs/workbench/contrib/accessibility/browser/accessibilityConfiguration';
3636
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
3737
import { AccessibilityCommandId } from 'vs/workbench/contrib/accessibility/common/accessibilityCommands';
38+
import { LayoutableEditor } from 'vs/workbench/contrib/comments/browser/simpleCommentEditor';
3839

3940
export const COMMENTEDITOR_DECORATION_KEY = 'commenteditordecoration';
4041

@@ -60,6 +61,7 @@ export class CommentThreadWidget<T extends IRange | ICellRange = IRange> extends
6061
}
6162
constructor(
6263
readonly container: HTMLElement,
64+
readonly _parentEditor: LayoutableEditor,
6365
private _owner: string,
6466
private _parentResourceUri: URI,
6567
private _contextKeyService: IContextKeyService,
@@ -126,6 +128,7 @@ export class CommentThreadWidget<T extends IRange | ICellRange = IRange> extends
126128
}));
127129
this._body = this._scopedInstantiationService.createInstance(
128130
CommentThreadBody,
131+
this._parentEditor,
129132
this._owner,
130133
this._parentResourceUri,
131134
bodyElement,
@@ -286,6 +289,7 @@ export class CommentThreadWidget<T extends IRange | ICellRange = IRange> extends
286289
CommentReply,
287290
this._owner,
288291
this._body.container,
292+
this._parentEditor,
289293
this._commentThread,
290294
this._scopedInstantiationService,
291295
this._contextKeyService,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
220220
this._commentThreadWidget = this._scopedInstantiationService.createInstance(
221221
CommentThreadWidget,
222222
container,
223+
this.editor,
223224
this._owner,
224225
this.editor.getModel()!.uri,
225226
this._contextKeyService,

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ export const ctxCommentEditorFocused = new RawContextKey<boolean>('commentEditor
3131
export const STARTING_EDITOR_HEIGHT = 5 * 18;
3232
export const MAX_EDITOR_HEIGHT = 25 * 18;
3333

34+
export interface LayoutableEditor {
35+
getLayoutInfo(): { height: number };
36+
}
37+
3438
export class SimpleCommentEditor extends CodeEditorWidget {
3539
private _parentThread: ICommentThreadWidget;
3640
private _commentEditorFocused: IContextKey<boolean>;
@@ -113,14 +117,15 @@ export class SimpleCommentEditor extends CodeEditorWidget {
113117
}
114118
}
115119

116-
export function calculateEditorHeight(editor: ICodeEditor, currentHeight: number): number {
120+
export function calculateEditorHeight(parentEditor: LayoutableEditor, editor: ICodeEditor, currentHeight: number): number {
117121
const layoutInfo = editor.getLayoutInfo();
118122
const lineHeight = editor.getOption(EditorOption.lineHeight);
119123
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.
120124
if ((contentHeight > layoutInfo.height) ||
121125
(contentHeight < layoutInfo.height && currentHeight > STARTING_EDITOR_HEIGHT)) {
122126
const linesToAdd = Math.ceil((contentHeight - layoutInfo.height) / lineHeight);
123-
const newEditorHeight = Math.min(MAX_EDITOR_HEIGHT, layoutInfo.height + (lineHeight * linesToAdd));
127+
const maxCommentEditorHeight = Math.max(Math.min(MAX_EDITOR_HEIGHT, parentEditor.getLayoutInfo().height - 90), STARTING_EDITOR_HEIGHT);
128+
const newEditorHeight = Math.min(maxCommentEditorHeight, layoutInfo.height + (lineHeight * linesToAdd));
124129
return newEditorHeight;
125130
}
126131
return currentHeight;

src/vs/workbench/contrib/notebook/browser/view/cellParts/cellComments.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export class CellComments extends CellContentPart {
6363
this._commentThreadWidget = this.instantiationService.createInstance(
6464
CommentThreadWidget,
6565
this.container,
66+
this.notebookEditor,
6667
owner,
6768
this.notebookEditor.textModel!.uri,
6869
this.contextKeyService,

0 commit comments

Comments
 (0)