Skip to content

Commit

Permalink
Fix comment editor min height
Browse files Browse the repository at this point in the history
  • Loading branch information
alexr00 committed Sep 29, 2023
1 parent 9e9b514 commit 3ff9df9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 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 { LayoutableEditor, STARTING_EDITOR_HEIGHT, SimpleCommentEditor, calculateEditorHeight } from 'vs/workbench/contrib/comments/browser/simpleCommentEditor';
import { LayoutableEditor, MIN_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 @@ -72,7 +72,7 @@ export class CommentNode<T extends IRange | ICellRange> extends Disposable {
private _commentEditor: SimpleCommentEditor | null = null;
private _commentEditorDisposables: IDisposable[] = [];
private _commentEditorModel: ITextModel | null = null;
private _editorHeight = STARTING_EDITOR_HEIGHT;
private _editorHeight = MIN_EDITOR_HEIGHT;

private _isPendingLabel!: HTMLElement;
private _timestamp: HTMLElement | undefined;
Expand Down
4 changes: 2 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 { LayoutableEditor, STARTING_EDITOR_HEIGHT, SimpleCommentEditor, calculateEditorHeight } from './simpleCommentEditor';
import { LayoutableEditor, MIN_EDITOR_HEIGHT, SimpleCommentEditor, calculateEditorHeight } from './simpleCommentEditor';

const COMMENT_SCHEME = 'comment';
let INMEM_MODEL_ID = 0;
Expand All @@ -45,7 +45,7 @@ export class CommentReply<T extends IRange | ICellRange> extends Disposable {
private _commentFormActions!: CommentFormActions;
private _commentEditorActions!: CommentFormActions;
private _reviewThreadReplyButton!: HTMLElement;
private _editorHeight = STARTING_EDITOR_HEIGHT;
private _editorHeight = MIN_EDITOR_HEIGHT;

constructor(
readonly owner: string,
Expand Down
10 changes: 5 additions & 5 deletions src/vs/workbench/contrib/comments/browser/simpleCommentEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ import { ILanguageConfigurationService } from 'vs/editor/common/languages/langua
import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { clamp } from 'vs/base/common/numbers';

export const ctxCommentEditorFocused = new RawContextKey<boolean>('commentEditorFocused', false);
export const STARTING_EDITOR_HEIGHT = 5 * 18;
export const MIN_EDITOR_HEIGHT = 5 * 18;
export const MAX_EDITOR_HEIGHT = 25 * 18;

export interface LayoutableEditor {
Expand Down Expand Up @@ -122,11 +123,10 @@ export function calculateEditorHeight(parentEditor: LayoutableEditor, editor: IC
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)) {
(contentHeight < layoutInfo.height && currentHeight > MIN_EDITOR_HEIGHT)) {
const linesToAdd = Math.ceil((contentHeight - layoutInfo.height) / lineHeight);
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;
const proposedHeight = layoutInfo.height + (lineHeight * linesToAdd);
return clamp(proposedHeight, MIN_EDITOR_HEIGHT, clamp(parentEditor.getLayoutInfo().height - 90, MIN_EDITOR_HEIGHT, MAX_EDITOR_HEIGHT));
}
return currentHeight;
}

0 comments on commit 3ff9df9

Please sign in to comment.