Skip to content

Commit 16268ba

Browse files
committed
Merge branch 'main' into aiday/inlineChatEndOfSelection
2 parents 19ee98f + b4e06ef commit 16268ba

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,13 @@ export class InlineChatController implements IEditorContribution {
202202
let widgetPosition: Position | undefined;
203203
if (initialRender) {
204204
widgetPosition = this._editor.getSelection().getEndPosition();
205+
this._zone.value.setMargins(widgetPosition);
205206
} else {
206207
widgetPosition = this._strategy.getWidgetPosition() ?? this._zone.value.position ?? this._activeSession.wholeRange.value.getEndPosition();
208+
const needsMargin = this._strategy.needsMargin();
209+
if (!needsMargin) {
210+
this._zone.value.setMargins(widgetPosition, 0);
211+
}
207212
}
208213
this._zone.value.show(widgetPosition);
209214
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ export abstract class EditModeStrategy {
4747
abstract hasFocus(): boolean;
4848

4949
abstract getWidgetPosition(): Position | undefined;
50+
51+
abstract needsMargin(): boolean;
5052
}
5153

5254
export class PreviewStrategy extends EditModeStrategy {
@@ -145,6 +147,10 @@ export class PreviewStrategy extends EditModeStrategy {
145147
hasFocus(): boolean {
146148
return this._widget.hasFocus();
147149
}
150+
151+
needsMargin(): boolean {
152+
return true;
153+
}
148154
}
149155

150156
class InlineDiffDecorations {
@@ -359,6 +365,10 @@ export class LiveStrategy extends EditModeStrategy {
359365
return lastLineOfLocalEdits ? new Position(lastLineOfLocalEdits, 1) : undefined;
360366
}
361367

368+
override needsMargin(): boolean {
369+
return Boolean(this._session.lastTextModelChanges.length);
370+
}
371+
362372
hasFocus(): boolean {
363373
return this._widget.hasFocus();
364374
}

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -795,13 +795,12 @@ export class InlineChatZoneWidget extends ZoneWidget {
795795
super.show(position, this._computeHeightInLines());
796796
this.widget.focus();
797797
this._ctxVisible.set(true);
798-
this._setMargins(position);
799798
}
800799

801-
private _setMargins(position: Position): void {
800+
private _calculateIndentationWidth(position: Position): number {
802801
const viewModel = this.editor._getViewModel();
803802
if (!viewModel) {
804-
return;
803+
return 0;
805804
}
806805
const visibleRange = viewModel.getCompletelyVisibleViewRange();
807806
const startLineVisibleRange = visibleRange.startLineNumber;
@@ -816,7 +815,17 @@ export class InlineChatZoneWidget extends ZoneWidget {
816815
break;
817816
}
818817
}
819-
this._indentationWidth = this.editor.getOffsetForColumn(indentationLineNumber ?? positionLine, indentationLevel ?? viewModel.getLineFirstNonWhitespaceColumn(positionLine));
818+
return this.editor.getOffsetForColumn(indentationLineNumber ?? positionLine, indentationLevel ?? viewModel.getLineFirstNonWhitespaceColumn(positionLine));
819+
}
820+
821+
setMargins(position: Position, indentationWidth?: number): void {
822+
if (indentationWidth === undefined) {
823+
indentationWidth = this._calculateIndentationWidth(position);
824+
}
825+
if (this._indentationWidth === indentationWidth) {
826+
return;
827+
}
828+
this._indentationWidth = indentationWidth;
820829
const info = this.editor.getLayoutInfo();
821830
const marginWithoutIndentation = info.glyphMarginWidth + info.decorationsWidth + info.lineNumbersWidth;
822831
const marginWithIndentation = marginWithoutIndentation + this._indentationWidth;

0 commit comments

Comments
 (0)