Skip to content

Commit 631e85c

Browse files
committed
Merge branch 'aiday/internalIssue4344' into aiday/positioningInlineChat
2 parents 13e2176 + 72d20c9 commit 631e85c

File tree

2 files changed

+42
-12
lines changed

2 files changed

+42
-12
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ export class InteractiveEditorController implements IEditorContribution {
269269
this._zone.value.widget.placeholder = this._getPlaceholderText();
270270
this._zone.value.widget.value = this._activeSession.lastInput ?? '';
271271
this._zone.value.widget.updateInfo(this._activeSession.session.message ?? localize('welcome.1', "AI-generated code may be incorrect"));
272-
this._zone.value.show(this._activeSession.wholeRange.value.getEndPosition());
272+
this._zone.value.show(this._activeSession.wholeRange.value);
273273
this._zone.value.widget.preferredExpansionState = this._activeSession.lastExpansionState;
274274

275275
this._sessionStore.add(this._editor.onDidChangeModel((e) => {
@@ -359,7 +359,7 @@ export class InteractiveEditorController implements IEditorContribution {
359359
assertType(this._activeSession);
360360

361361
this._zone.value.widget.placeholder = this._getPlaceholderText();
362-
this._zone.value.show(this._activeSession.wholeRange.value.getEndPosition());
362+
this._zone.value.show(this._activeSession.wholeRange.value);
363363

364364
if (options?.message) {
365365
this._zone.value.widget.value = options?.message;

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

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { EmbeddedCodeEditorWidget, EmbeddedDiffEditorWidget } from 'vs/editor/br
2626
import { HiddenItemStrategy, MenuWorkbenchToolBar } from 'vs/platform/actions/browser/toolbar';
2727
import { ProgressBar } from 'vs/base/browser/ui/progressbar/progressbar';
2828
import { SuggestController } from 'vs/editor/contrib/suggest/browser/suggestController';
29-
import { IPosition, Position } from 'vs/editor/common/core/position';
29+
import { Position } from 'vs/editor/common/core/position';
3030
import { DEFAULT_FONT_FAMILY } from 'vs/workbench/browser/style';
3131
import { DropdownWithDefaultActionViewItem, IMenuEntryActionViewItemOptions, MenuEntryActionViewItem, createActionViewItem } from 'vs/platform/actions/browser/menuEntryActionViewItem';
3232
import { CompletionItem, CompletionItemInsertTextRule, CompletionItemKind, CompletionItemProvider, CompletionList, ProviderResult, TextEdit } from 'vs/editor/common/languages';
@@ -716,6 +716,7 @@ export class InteractiveEditorZoneWidget extends ZoneWidget {
716716
private readonly _ctxVisible: IContextKey<boolean>;
717717
private readonly _ctxCursorPosition: IContextKey<'above' | 'below' | ''>;
718718
private _dimension?: Dimension;
719+
private _indentationWidth: number = 0;
719720

720721
constructor(
721722
editor: ICodeEditor,
@@ -762,19 +763,18 @@ export class InteractiveEditorZoneWidget extends ZoneWidget {
762763

763764
protected override _doLayout(heightInPixel: number): void {
764765

765-
const info = this.editor.getLayoutInfo();
766-
const spaceLeft = info.lineNumbersWidth + info.glyphMarginWidth + info.decorationsWidth;
767-
const spaceRight = info.minimap.minimapWidth + info.verticalScrollbarWidth;
768-
769766
const maxWidth = !this.widget.showsAnyPreview() ? 640 : Number.MAX_SAFE_INTEGER;
770-
const width = Math.min(maxWidth, info.contentWidth - (info.glyphMarginWidth + info.decorationsWidth));
767+
const width = Math.min(maxWidth, this._availableSpaceGivenIndentation());
771768
this._dimension = new Dimension(width, heightInPixel);
772-
this.widget.domNode.style.marginLeft = `${spaceLeft}px`;
773-
this.widget.domNode.style.marginRight = `${spaceRight}px`;
774769
this.widget.domNode.style.width = `${width}px`;
775770
this.widget.layout(this._dimension);
776771
}
777772

773+
private _availableSpaceGivenIndentation(): number {
774+
const info = this.editor.getLayoutInfo();
775+
return info.contentWidth - (info.glyphMarginWidth + info.decorationsWidth + this._indentationWidth);
776+
}
777+
778778
private _computeHeightInLines(): number {
779779
const lineHeight = this.editor.getOption(EditorOption.lineHeight);
780780
return this.widget.getHeight() / lineHeight;
@@ -787,10 +787,40 @@ export class InteractiveEditorZoneWidget extends ZoneWidget {
787787
super._relayout(this._computeHeightInLines());
788788
}
789789

790-
override show(where: IPosition): void {
791-
super.show(where, this._computeHeightInLines());
790+
override show(selectionRange: Range): void {
791+
super.show(selectionRange.getEndPosition(), this._computeHeightInLines());
792792
this.widget.focus();
793793
this._ctxVisible.set(true);
794+
this._setMargins(selectionRange);
795+
}
796+
797+
private _setMargins(selectionRange: Range): void {
798+
const info = this.editor.getLayoutInfo();
799+
const startLineNumber = selectionRange.getStartPosition().lineNumber;
800+
const endLineNumber = selectionRange.getEndPosition().lineNumber;
801+
const viewModel = this.editor._getViewModel();
802+
if (!viewModel) {
803+
return;
804+
}
805+
let indentationLineNumber;
806+
let indentationLevel;
807+
for (let lineNumber = endLineNumber; lineNumber >= startLineNumber; lineNumber--) {
808+
const currentIndentationLevel = viewModel.getLineFirstNonWhitespaceColumn(lineNumber);
809+
if (currentIndentationLevel !== 0) {
810+
indentationLineNumber = lineNumber;
811+
indentationLevel = currentIndentationLevel;
812+
break;
813+
}
814+
}
815+
this._indentationWidth = this.editor.getOffsetForColumn(indentationLineNumber ?? endLineNumber, indentationLevel ?? viewModel.getLineFirstNonWhitespaceColumn(endLineNumber));
816+
const marginWithoutIndentation = info.glyphMarginWidth + info.decorationsWidth + info.lineNumbersWidth;
817+
const marginWithIndentation = marginWithoutIndentation + this._indentationWidth;
818+
const isEnoughAvailableSpaceWithIndentation = this._availableSpaceGivenIndentation() > 400;
819+
this._indentationWidth = isEnoughAvailableSpaceWithIndentation ? this._indentationWidth : 0;
820+
const spaceLeft = isEnoughAvailableSpaceWithIndentation ? marginWithIndentation : marginWithoutIndentation;
821+
const spaceRight = info.minimap.minimapWidth + info.verticalScrollbarWidth;
822+
this.widget.domNode.style.marginLeft = `${spaceLeft}px`;
823+
this.widget.domNode.style.marginRight = `${spaceRight}px`;
794824
}
795825

796826
override hide(): void {

0 commit comments

Comments
 (0)