Skip to content

Commit 57562a8

Browse files
authored
set notebook inline chat height based on full notebook editor height (microsoft#257332)
* notebook inline chat height based on full notebook editor height * just pass optional param
1 parent cf84bbe commit 57562a8

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import { IFileService } from '../../../../platform/files/common/files.js';
6363
import { IChatAttachmentResolveService } from '../../chat/browser/chatAttachmentResolveService.js';
6464
import { INotebookService } from '../../notebook/common/notebookService.js';
6565
import { ICellEditOperation } from '../../notebook/common/notebookCommon.js';
66+
import { INotebookEditor } from '../../notebook/browser/notebookBrowser.js';
6667

6768
export const enum State {
6869
CREATE_SESSION = 'CREATE_SESSION',
@@ -242,16 +243,18 @@ export class InlineChatController1 implements IEditorContribution {
242243
// check if this editor is part of a notebook editor
243244
// and iff so, use the notebook location but keep the resolveData
244245
// talk about editor data
245-
for (const notebookEditor of notebookEditorService.listNotebookEditors()) {
246-
for (const [, codeEditor] of notebookEditor.codeEditors) {
246+
let notebookEditor: INotebookEditor | undefined;
247+
for (const editor of notebookEditorService.listNotebookEditors()) {
248+
for (const [, codeEditor] of editor.codeEditors) {
247249
if (codeEditor === this._editor) {
250+
notebookEditor = editor;
248251
location.location = ChatAgentLocation.Notebook;
249252
break;
250253
}
251254
}
252255
}
253256

254-
const zone = _instaService.createInstance(InlineChatZoneWidget, location, undefined, this._editor);
257+
const zone = _instaService.createInstance(InlineChatZoneWidget, location, undefined, { editor: this._editor, notebookEditor });
255258
this._store.add(zone);
256259
this._store.add(zone.widget.chatWidget.onDidClear(async () => {
257260
const r = this.joinCurrentRun();
@@ -1260,12 +1263,13 @@ export class InlineChatController2 implements IEditorContribution {
12601263

12611264
// inline chat in notebooks
12621265
// check if this editor is part of a notebook editor
1263-
// and iff so, use the notebook location but keep the resolveData
1264-
// talk about editor data
1265-
for (const notebookEditor of this._notebookEditorService.listNotebookEditors()) {
1266-
for (const [, codeEditor] of notebookEditor.codeEditors) {
1266+
// if so, update the location and use the notebook specific widget
1267+
let notebookEditor: INotebookEditor | undefined;
1268+
for (const editor of this._notebookEditorService.listNotebookEditors()) {
1269+
for (const [, codeEditor] of editor.codeEditors) {
12671270
if (codeEditor === this._editor) {
12681271
location.location = ChatAgentLocation.Notebook;
1272+
notebookEditor = editor;
12691273
break;
12701274
}
12711275
}
@@ -1279,7 +1283,7 @@ export class InlineChatController2 implements IEditorContribution {
12791283
renderTextEditsAsSummary: _uri => true
12801284
}
12811285
},
1282-
this._editor
1286+
{ editor: this._editor, notebookEditor },
12831287
);
12841288

12851289
result.domNode.classList.add('inline-chat-2');

src/vs/workbench/contrib/inlineChat/browser/inlineChatZoneWidget.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { ILogService } from '../../../../platform/log/common/log.js';
2222
import { IChatWidgetViewOptions } from '../../chat/browser/chat.js';
2323
import { IChatWidgetLocationOptions } from '../../chat/browser/chatWidget.js';
2424
import { isResponseVM } from '../../chat/common/chatViewModel.js';
25+
import { INotebookEditor } from '../../notebook/browser/notebookBrowser.js';
2526
import { ACTION_REGENERATE_RESPONSE, ACTION_REPORT_ISSUE, ACTION_TOGGLE_DIFF, CTX_INLINE_CHAT_OUTER_CURSOR_POSITION, MENU_INLINE_CHAT_SIDE, MENU_INLINE_CHAT_WIDGET_SECONDARY, MENU_INLINE_CHAT_WIDGET_STATUS } from '../common/inlineChat.js';
2627
import { EditorBasedInlineChatWidget } from './inlineChatWidget.js';
2728

@@ -45,16 +46,18 @@ export class InlineChatZoneWidget extends ZoneWidget {
4546
private readonly _scrollUp = this._disposables.add(new ScrollUpState(this.editor));
4647
private readonly _ctxCursorPosition: IContextKey<'above' | 'below' | ''>;
4748
private _dimension?: Dimension;
49+
private notebookEditor?: INotebookEditor;
4850

4951
constructor(
5052
location: IChatWidgetLocationOptions,
5153
options: IChatWidgetViewOptions | undefined,
52-
editor: ICodeEditor,
54+
editors: { editor: ICodeEditor; notebookEditor?: INotebookEditor },
5355
@IInstantiationService private readonly _instaService: IInstantiationService,
5456
@ILogService private _logService: ILogService,
5557
@IContextKeyService contextKeyService: IContextKeyService,
5658
) {
57-
super(editor, InlineChatZoneWidget._options);
59+
super(editors.editor, InlineChatZoneWidget._options);
60+
this.notebookEditor = editors.notebookEditor;
5861

5962
this._ctxCursorPosition = CTX_INLINE_CHAT_OUTER_CURSOR_POSITION.bindTo(contextKeyService);
6063

@@ -87,7 +90,7 @@ export class InlineChatZoneWidget extends ZoneWidget {
8790
rendererOptions: {
8891
renderTextEditsAsSummary: (uri) => {
8992
// render when dealing with the current file in the editor
90-
return isEqual(uri, editor.getModel()?.uri);
93+
return isEqual(uri, editors.editor.getModel()?.uri);
9194
},
9295
renderDetectedCommandsWithRequest: true,
9396
...options?.rendererOptions
@@ -165,7 +168,7 @@ export class InlineChatZoneWidget extends ZoneWidget {
165168

166169
private _computeHeight(): { linesValue: number; pixelsValue: number } {
167170
const chatContentHeight = this.widget.contentHeight;
168-
const editorHeight = this.editor.getLayoutInfo().height;
171+
const editorHeight = this.notebookEditor?.getLayoutInfo().height ?? this.editor.getLayoutInfo().height;
169172

170173
const contentHeight = this._decoratingElementsHeight() + Math.min(chatContentHeight, Math.max(this.widget.minHeight, editorHeight * 0.42));
171174
const heightInLines = contentHeight / this.editor.getOption(EditorOption.lineHeight);

0 commit comments

Comments
 (0)