Skip to content

Commit 977b6a1

Browse files
authored
Merge pull request microsoft#185241 from microsoft/aiday/changingTheInlineChatBackgroundColor
Making zone widget background same as selection if inside of the selection
2 parents 61ba389 + 653e8d0 commit 977b6a1

File tree

3 files changed

+38
-18
lines changed

3 files changed

+38
-18
lines changed

src/vs/workbench/contrib/inlineChat/browser/inlineChat.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
z-index: 3;
88
}
99

10+
.monaco-editor .zone-widget-container.inside-selection {
11+
background-color: var(--vscode-inlineChat-regionHighlight);
12+
}
13+
1014
.monaco-editor .inline-chat {
1115
color: inherit;
1216
padding: 6px;

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,17 @@ export class InlineChatController implements IEditorContribution {
200200
let widgetPosition: Position;
201201
if (initialRender) {
202202
widgetPosition = this._editor.getSelection().getEndPosition();
203-
this._zone.value.setMargins(widgetPosition);
203+
this._zone.value.setContainerMargins();
204+
this._zone.value.setWidgetMargins(widgetPosition);
204205
} else {
205206
assertType(this._activeSession);
206207
assertType(this._strategy);
207208
widgetPosition = this._strategy.getWidgetPosition() ?? this._zone.value.position ?? this._activeSession.wholeRange.value.getEndPosition();
208209
const needsMargin = this._strategy.needsMargin();
209210
if (!needsMargin) {
210-
this._zone.value.setMargins(widgetPosition, 0);
211+
this._zone.value.setWidgetMargins(widgetPosition, 0);
211212
}
213+
this._zone.value.updateBackgroundColor(widgetPosition, this._activeSession.wholeRange.value);
212214
}
213215
this._zone.value.show(widgetPosition);
214216
}

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

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import 'vs/css!./inlineChat';
77
import { DisposableStore, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle';
88
import { IActiveCodeEditor, ICodeEditor, IDiffEditorConstructionOptions } from 'vs/editor/browser/editorBrowser';
9-
import { EditorOption } from 'vs/editor/common/config/editorOptions';
10-
import { Range } from 'vs/editor/common/core/range';
9+
import { EditorLayoutInfo, EditorOption } from 'vs/editor/common/config/editorOptions';
10+
import { IRange, Range } from 'vs/editor/common/core/range';
1111
import { localize } from 'vs/nls';
1212
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
1313
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
@@ -744,15 +744,15 @@ export class InlineChatZoneWidget extends ZoneWidget {
744744
protected override _doLayout(heightInPixel: number): void {
745745

746746
const maxWidth = !this.widget.showsAnyPreview() ? 640 : Number.MAX_SAFE_INTEGER;
747-
const width = Math.min(maxWidth, this._availableSpaceGivenIndentation());
747+
const width = Math.min(maxWidth, this._availableSpaceGivenIndentation(this._indentationWidth));
748748
this._dimension = new Dimension(width, heightInPixel);
749749
this.widget.domNode.style.width = `${width}px`;
750750
this.widget.layout(this._dimension);
751751
}
752752

753-
private _availableSpaceGivenIndentation(): number {
753+
private _availableSpaceGivenIndentation(indentationWidth: number | undefined): number {
754754
const info = this.editor.getLayoutInfo();
755-
return info.contentWidth - (info.glyphMarginWidth + info.decorationsWidth + (this._indentationWidth ?? 0));
755+
return info.contentWidth - (info.glyphMarginWidth + info.decorationsWidth + (indentationWidth ?? 0));
756756
}
757757

758758
private _computeHeightInLines(): number {
@@ -773,6 +773,18 @@ export class InlineChatZoneWidget extends ZoneWidget {
773773
this._ctxVisible.set(true);
774774
}
775775

776+
override _getWidth(info: EditorLayoutInfo): number {
777+
return info.width - info.minimap.minimapWidth;
778+
}
779+
780+
public updateBackgroundColor(position: Position, selection: IRange) {
781+
if (!this.container) {
782+
return;
783+
}
784+
const widgetLineNumber = position.lineNumber;
785+
this.container.classList.toggle('inside-selection', widgetLineNumber >= selection.startLineNumber && widgetLineNumber < selection.endLineNumber);
786+
}
787+
776788
private _calculateIndentationWidth(position: Position): number {
777789
const viewModel = this.editor._getViewModel();
778790
if (!viewModel) {
@@ -794,23 +806,25 @@ export class InlineChatZoneWidget extends ZoneWidget {
794806
return this.editor.getOffsetForColumn(indentationLineNumber ?? positionLine, indentationLevel ?? viewModel.getLineFirstNonWhitespaceColumn(positionLine));
795807
}
796808

797-
setMargins(position: Position, indentationWidth?: number): void {
809+
setContainerMargins(): void {
810+
if (!this.container) {
811+
return;
812+
}
813+
const info = this.editor.getLayoutInfo();
814+
const marginWithoutIndentation = info.glyphMarginWidth + info.decorationsWidth + info.lineNumbersWidth;
815+
this.container.style.marginLeft = `${marginWithoutIndentation}px`;
816+
}
817+
818+
setWidgetMargins(position: Position, indentationWidth?: number): void {
798819
if (indentationWidth === undefined) {
799820
indentationWidth = this._calculateIndentationWidth(position);
800821
}
801822
if (this._indentationWidth === indentationWidth) {
802823
return;
803824
}
804-
this._indentationWidth = indentationWidth;
805-
const info = this.editor.getLayoutInfo();
806-
const marginWithoutIndentation = info.glyphMarginWidth + info.decorationsWidth + info.lineNumbersWidth;
807-
const marginWithIndentation = marginWithoutIndentation + this._indentationWidth;
808-
const isEnoughAvailableSpaceWithIndentation = this._availableSpaceGivenIndentation() > 400;
809-
this._indentationWidth = isEnoughAvailableSpaceWithIndentation ? this._indentationWidth : 0;
810-
const spaceLeft = isEnoughAvailableSpaceWithIndentation ? marginWithIndentation : marginWithoutIndentation;
811-
const spaceRight = info.minimap.minimapWidth + info.verticalScrollbarWidth;
812-
this.widget.domNode.style.marginLeft = `${spaceLeft}px`;
813-
this.widget.domNode.style.marginRight = `${spaceRight}px`;
825+
this._indentationWidth = this._availableSpaceGivenIndentation(indentationWidth) > 400 ? indentationWidth : 0;
826+
this.widget.domNode.style.marginLeft = `${this._indentationWidth}px`;
827+
this.widget.domNode.style.marginRight = `${this.editor.getLayoutInfo().minimap.minimapWidth}px`;
814828
}
815829

816830
override hide(): void {

0 commit comments

Comments
 (0)