Skip to content

Commit 363ab72

Browse files
committed
cleaning the code
1 parent 07465d7 commit 363ab72

File tree

4 files changed

+38
-38
lines changed

4 files changed

+38
-38
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 & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import { INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/se
3838
import { CellUri } from 'vs/workbench/contrib/notebook/common/notebookCommon';
3939
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
4040
import { Lazy } from 'vs/base/common/lazy';
41-
import { Selection } from 'vs/editor/common/core/selection';
4241

4342
export const enum State {
4443
CREATE_SESSION = 'CREATE_SESSION',
@@ -101,7 +100,6 @@ export class InlineChatController implements IEditorContribution {
101100
private _activeSession?: Session;
102101
private _strategy?: EditModeStrategy;
103102
private _ignoreModelContentChanged = false;
104-
private _selection: Selection | undefined;
105103

106104
constructor(
107105
private readonly _editor: ICodeEditor,
@@ -201,34 +199,20 @@ export class InlineChatController implements IEditorContribution {
201199
assertType(this._strategy);
202200
assertType(this._editor.hasModel());
203201

204-
const info = this._editor.getLayoutInfo();
205-
const marginWithoutIndentation = info.glyphMarginWidth + info.decorationsWidth + info.lineNumbersWidth;
206-
this._zone.value.container!.style.marginLeft = `${marginWithoutIndentation}px`;
207-
208202
let widgetPosition: Position | undefined;
209203
if (initialRender) {
210-
this._selection = this._editor.getSelection();
211204
widgetPosition = this._editor.getSelection().getEndPosition();
212-
this._zone.value.setMargins(widgetPosition);
213-
console.log('widgetPosition : ', widgetPosition);
214-
console.log('selection : ', this._editor.getSelection());
205+
this._zone.value.setContainerMargins();
206+
this._zone.value.setWidgetMargins(widgetPosition);
215207
} else {
216208
widgetPosition = this._strategy.getWidgetPosition() ?? this._zone.value.position ?? this._activeSession.wholeRange.value.getEndPosition();
217209
const needsMargin = this._strategy.needsMargin();
218210
if (!needsMargin) {
219-
this._zone.value.setMargins(widgetPosition, 0);
220-
}
221-
// TODO: clean up
222-
const widgetLineNumber = widgetPosition.lineNumber;
223-
if (this._selection && widgetLineNumber >= this._selection.startLineNumber && widgetLineNumber < this._selection.endLineNumber) {
224-
console.log('this._zone.value.container : ', this._zone.value.container);
225-
this._zone.value.container!.style.backgroundColor = `var(--vscode-inlineChat-regionHighlight)`;
211+
this._zone.value.setWidgetMargins(widgetPosition, 0);
226212
}
227-
console.log('widgetPosition : ', widgetPosition);
228-
console.log('selection : ', this._editor.getSelection());
229-
console.log('this._activeSession.wholeRange : ', this._activeSession.wholeRange);
230213
}
231214
this._zone.value.show(widgetPosition);
215+
this._zone.value.updateBackgroundColor(widgetPosition, this._activeSession.selection);
232216
}
233217

234218
protected async _nextState(state: State, options: InlineChatRunOptions | undefined): Promise<void> {
@@ -301,7 +285,6 @@ export class InlineChatController implements IEditorContribution {
301285
range: this._activeSession.wholeRange.value,
302286
options: InlineChatController._decoBlock
303287
}]);
304-
console.log('wholeRangeDecoration', wholeRangeDecoration);
305288
this._sessionStore.add(toDisposable(() => wholeRangeDecoration.clear()));
306289

307290
this._zone.value.widget.updateSlashCommands(this._activeSession.session.slashCommands ?? []);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ export class Session {
126126
readonly textModelN: ITextModel,
127127
readonly provider: IInlineChatSessionProvider,
128128
readonly session: IInlineChatSession,
129-
readonly wholeRange: SessionWholeRange
129+
readonly wholeRange: SessionWholeRange,
130+
readonly selection: IRange
130131
) {
131132
this.textModelNAltVersion = textModelN.getAlternativeVersionId();
132133
this._teldata = {
@@ -443,7 +444,7 @@ export class InlineChatSessionService implements IInlineChatSessionService {
443444
const wholeRangeMgr = new SessionWholeRange(textModel, wholeRange);
444445
store.add(wholeRangeMgr);
445446

446-
const session = new Session(options.editMode, editor, textModel0, textModel, provider, raw, wholeRangeMgr);
447+
const session = new Session(options.editMode, editor, textModel0, textModel, provider, raw, wholeRangeMgr, editor.getSelection());
447448

448449
// store: key -> session
449450
const key = this._key(editor, textModel.uri);

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

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'vs/css!./inlineChat';
77
import { DisposableStore, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle';
88
import { IActiveCodeEditor, ICodeEditor, IDiffEditorConstructionOptions } from 'vs/editor/browser/editorBrowser';
99
import { EditorOption } from 'vs/editor/common/config/editorOptions';
10-
import { Range } from 'vs/editor/common/core/range';
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';
@@ -47,8 +47,8 @@ import { AccessibilityVerbositySettingId } from 'vs/workbench/contrib/accessibil
4747
import { renderLabelWithIcons } from 'vs/base/browser/ui/iconLabel/iconLabels';
4848
import { ExpansionState } from 'vs/workbench/contrib/inlineChat/browser/inlineChatSession';
4949
import { IdleValue } from 'vs/base/common/async';
50-
import * as aria from 'vs/base/browser/ui/aria/aria';
5150
import { IMenuWorkbenchButtonBarOptions, MenuWorkbenchButtonBar } from 'vs/platform/actions/browser/buttonbar';
51+
import * as aria from 'vs/base/browser/ui/aria/aria';
5252

5353
const defaultAriaLabel = localize('aria-label', "Inline Chat Input");
5454

@@ -740,17 +740,17 @@ export class InlineChatZoneWidget extends ZoneWidget {
740740

741741

742742
protected override _doLayout(heightInPixel: number): void {
743-
console.log('inside of _doLayout');
743+
744744
const maxWidth = !this.widget.showsAnyPreview() ? 640 : Number.MAX_SAFE_INTEGER;
745-
const width = Math.min(maxWidth, this._availableSpaceGivenIndentation());
745+
const width = Math.min(maxWidth, this._availableSpaceGivenIndentation(this._indentationWidth));
746746
this._dimension = new Dimension(width, heightInPixel);
747747
this.widget.domNode.style.width = `${width}px`;
748748
this.widget.layout(this._dimension);
749749
}
750750

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

756756
private _computeHeightInLines(): number {
@@ -771,6 +771,14 @@ export class InlineChatZoneWidget extends ZoneWidget {
771771
this._ctxVisible.set(true);
772772
}
773773

774+
public updateBackgroundColor(position: Position, selection: IRange) {
775+
if (!this.container) {
776+
return;
777+
}
778+
const widgetLineNumber = position.lineNumber;
779+
this.container.classList.toggle('inside-selection', widgetLineNumber >= selection.startLineNumber && widgetLineNumber < selection.endLineNumber);
780+
}
781+
774782
private _calculateIndentationWidth(position: Position): number {
775783
const viewModel = this.editor._getViewModel();
776784
if (!viewModel) {
@@ -792,21 +800,25 @@ export class InlineChatZoneWidget extends ZoneWidget {
792800
return this.editor.getOffsetForColumn(indentationLineNumber ?? positionLine, indentationLevel ?? viewModel.getLineFirstNonWhitespaceColumn(positionLine));
793801
}
794802

795-
setMargins(position: Position, indentationWidth?: number): void {
803+
setContainerMargins(): void {
804+
if (!this.container) {
805+
return;
806+
}
807+
const info = this.editor.getLayoutInfo();
808+
const marginWithoutIndentation = info.glyphMarginWidth + info.decorationsWidth + info.lineNumbersWidth;
809+
this.container.style.marginLeft = `${marginWithoutIndentation}px`;
810+
}
811+
812+
setWidgetMargins(position: Position, indentationWidth?: number): void {
796813
if (indentationWidth === undefined) {
797814
indentationWidth = this._calculateIndentationWidth(position);
798815
}
799816
if (this._indentationWidth === indentationWidth) {
800817
return;
801818
}
802-
this._indentationWidth = indentationWidth;
803-
const info = this.editor.getLayoutInfo();
804-
const isEnoughAvailableSpaceWithIndentation = this._availableSpaceGivenIndentation() > 400;
805-
this._indentationWidth = isEnoughAvailableSpaceWithIndentation ? this._indentationWidth : 0;
806-
const spaceLeft = isEnoughAvailableSpaceWithIndentation ? this._indentationWidth : 0;
807-
const spaceRight = info.minimap.minimapWidth;
808-
this.widget.domNode.style.marginLeft = `${spaceLeft}px`;
809-
this.widget.domNode.style.marginRight = `${spaceRight}px`;
819+
this._indentationWidth = this._availableSpaceGivenIndentation(indentationWidth) > 400 ? indentationWidth : 0;
820+
this.widget.domNode.style.marginLeft = `${this._indentationWidth}px`;
821+
this.widget.domNode.style.marginRight = `${this.editor.getLayoutInfo().minimap.minimapWidth}px`;
810822
}
811823

812824
override hide(): void {

0 commit comments

Comments
 (0)