Skip to content

Commit 1c22e0e

Browse files
committed
code after review
1 parent 37a093c commit 1c22e0e

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
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: 23 additions & 19 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';
@@ -763,29 +763,13 @@ export class InteractiveEditorZoneWidget extends ZoneWidget {
763763
protected override _doLayout(heightInPixel: number): void {
764764

765765
const info = this.editor.getLayoutInfo();
766-
const spaceLeft = info.lineNumbersWidth + info.glyphMarginWidth + info.decorationsWidth + (this._findApproximateIndentationWidth() ?? 0);
767-
const spaceRight = info.minimap.minimapWidth + info.verticalScrollbarWidth;
768-
769766
const maxWidth = !this.widget.showsAnyPreview() ? 640 : Number.MAX_SAFE_INTEGER;
770767
const width = Math.min(maxWidth, info.contentWidth - (info.glyphMarginWidth + info.decorationsWidth));
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

778-
private _findApproximateIndentationWidth(): number | undefined {
779-
if (!this.position) {
780-
return;
781-
}
782-
const lineIndentColumn = this.editor._getViewModel()?.getLineIndentColumn(this.position.lineNumber);
783-
if (!lineIndentColumn) {
784-
return;
785-
}
786-
return (lineIndentColumn - 1) * this.editor.getOption(EditorOption.fontSize);
787-
}
788-
789773
private _computeHeightInLines(): number {
790774
const lineHeight = this.editor.getOption(EditorOption.lineHeight);
791775
return this.widget.getHeight() / lineHeight;
@@ -798,10 +782,30 @@ export class InteractiveEditorZoneWidget extends ZoneWidget {
798782
super._relayout(this._computeHeightInLines());
799783
}
800784

801-
override show(where: IPosition): void {
802-
super.show(where, this._computeHeightInLines());
785+
override show(selectionRange: Range): void {
786+
super.show(selectionRange.getEndPosition(), this._computeHeightInLines());
803787
this.widget.focus();
804788
this._ctxVisible.set(true);
789+
this._setMargins(selectionRange);
790+
}
791+
792+
private _setMargins(selectionRange: Range): void {
793+
const info = this.editor.getLayoutInfo();
794+
const startLineNumber = selectionRange.getStartPosition().lineNumber;
795+
const endLineNumber = selectionRange.getEndPosition().lineNumber;
796+
let lineNumberForIndentation = endLineNumber;
797+
for (let lineNumber = endLineNumber; lineNumber >= startLineNumber; lineNumber--) {
798+
const lineContent = this.editor.getModel()?.getLineContent(lineNumber);
799+
if (lineContent !== '') {
800+
lineNumberForIndentation = lineNumber;
801+
break;
802+
}
803+
}
804+
const indentationLevel = this.editor._getViewModel()?.getLineFirstNonWhitespaceColumn(lineNumberForIndentation);
805+
const spaceLeft = info.lineNumbersWidth + info.glyphMarginWidth + info.decorationsWidth + (indentationLevel ? this.editor.getOffsetForColumn(lineNumberForIndentation, indentationLevel) : 0);
806+
const spaceRight = info.minimap.minimapWidth + info.verticalScrollbarWidth;
807+
this.widget.domNode.style.marginLeft = `${spaceLeft}px`;
808+
this.widget.domNode.style.marginRight = `${spaceRight}px`;
805809
}
806810

807811
override hide(): void {

0 commit comments

Comments
 (0)