Skip to content

Commit 561854e

Browse files
committed
making the position be reset on update edit mode
1 parent e05a47d commit 561854e

File tree

1 file changed

+45
-7
lines changed

1 file changed

+45
-7
lines changed

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

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ export interface InteractiveEditorRunOptions {
6767
autoSend?: boolean;
6868
existingSession?: Session;
6969
isUnstashed?: boolean;
70-
initialRender?: boolean;
7170
}
7271

7372
export class InteractiveEditorController implements IEditorContribution {
@@ -238,12 +237,16 @@ export class InteractiveEditorController implements IEditorContribution {
238237
this._initializeStratetgy(session);
239238
this._activeSession = session;
240239
this._store.add(this._configurationService.onDidChangeConfiguration((e) => {
240+
241241
console.log('e : ', e);
242242
console.log('e.affectsConfiguration(interactiveEditor.editModes) : ', e.affectsConfiguration('interactiveEditor.editMode'));
243243
console.log('this._activeSession : ', this._activeSession);
244+
244245
if (e.affectsConfiguration('interactiveEditor.editMode')) {
246+
245247
console.log('entered into inner if loop of onDidChangeConfiguration');
246248
console.log('this._getMode() : ', this._getMode());
249+
247250
this._updateEditMode = true;
248251
}
249252
}));
@@ -252,7 +255,9 @@ export class InteractiveEditorController implements IEditorContribution {
252255
}
253256

254257
private _initializeStratetgy(session: Session): void {
258+
255259
console.log('inside of initial strategy');
260+
256261
switch (session.editMode) {
257262
case EditMode.Live:
258263
this._strategy = this._instaService.createInstance(LiveStrategy, session, this._editor, this._zone.value.widget);
@@ -267,24 +272,49 @@ export class InteractiveEditorController implements IEditorContribution {
267272
}
268273
}
269274

270-
private _showWidget(initialRender: boolean = false) {
275+
private _showWidget(initialRender: boolean = false, updateEditMode: boolean = false) {
276+
271277
console.log('inside of _showWidget');
272278
console.log('initialRender : ', initialRender);
279+
console.log('updateEditMode : ', updateEditMode);
280+
273281
assertType(this._activeSession);
274282
const selectionRange = this._activeSession.wholeRange.value;
275283

276284
if (!initialRender) {
285+
console.log('initial render is false');
286+
console.log('this._activeSession.lastPosition : ', this._activeSession.lastPosition);
277287
if (this._activeSession.lastPosition) {
278-
this._zone.value.showWidget(selectionRange, this._activeSession.lastPosition);
288+
console.log('inside if');
289+
if (updateEditMode) {
290+
console.log('inside if');
291+
this._zone.value.showWidget(selectionRange, this._strategy?.getWidgetPosition(initialRender, selectionRange));
292+
} else {
293+
console.log('inside else');
294+
this._zone.value.showWidget(selectionRange, this._activeSession.lastPosition);
295+
}
279296
} else {
297+
console.log('inside else');
280298
const widgetPosition = this._strategy?.getWidgetPosition(initialRender, selectionRange);
281299
this._activeSession.lastPosition = widgetPosition;
282300
this._zone.value.showWidget(selectionRange, widgetPosition);
283301
}
284302
} else {
303+
console.log('initial render is true');
304+
console.log('this._activeSession.lastPosition : ', this._activeSession.lastPosition);
305+
285306
if (this._activeSession.lastPosition) {
286-
this._zone.value.showWidget(selectionRange, this._activeSession.lastPosition);
307+
console.log('inside if');
308+
if (updateEditMode) {
309+
console.log('inside if');
310+
this._zone.value.showWidget(selectionRange, this._strategy?.getWidgetPosition(initialRender, selectionRange));
311+
this._activeSession.lastPosition = undefined;
312+
} else {
313+
console.log('inside else');
314+
this._zone.value.showWidget(selectionRange, this._activeSession.lastPosition);
315+
}
287316
} else {
317+
console.log('inside else');
288318
this._zone.value.showWidget(selectionRange, this._strategy?.getWidgetPosition(initialRender, selectionRange));
289319
}
290320
}
@@ -296,7 +326,6 @@ export class InteractiveEditorController implements IEditorContribution {
296326
if (this._updateEditMode) {
297327
this._activeSession.editMode = this._getMode();
298328
this._initializeStratetgy(this._activeSession);
299-
this._updateEditMode = false;
300329
}
301330

302331
// hide/cancel inline completions when invoking IE
@@ -317,9 +346,11 @@ export class InteractiveEditorController implements IEditorContribution {
317346
this._zone.value.widget.value = this._activeSession.lastInput ?? '';
318347
this._zone.value.widget.updateInfo(this._activeSession.session.message ?? localize('welcome.1', "AI-generated code may be incorrect"));
319348
this._zone.value.widget.preferredExpansionState = this._activeSession.lastExpansionState;
349+
320350
console.log('inside of init ui before show widget');
351+
321352
this._initialRender = true;
322-
this._showWidget(this._initialRender);
353+
this._showWidget(this._initialRender, this._updateEditMode);
323354

324355
this._sessionStore.add(this._editor.onDidChangeModel((e) => {
325356
const msg = this._activeSession?.lastExchange
@@ -407,10 +438,13 @@ export class InteractiveEditorController implements IEditorContribution {
407438
private async [State.WAIT_FOR_INPUT](options: InteractiveEditorRunOptions | undefined): Promise<State.ACCEPT | State.CANCEL | State.PAUSE | State.WAIT_FOR_INPUT | State.MAKE_REQUEST> {
408439
assertType(this._activeSession);
409440

441+
410442
console.log('inside of wait for input');
443+
411444
this._zone.value.widget.placeholder = this._getPlaceholderText();
412-
this._showWidget(this._initialRender);
445+
this._showWidget(this._initialRender, this._updateEditMode);
413446
this._initialRender = false;
447+
this._updateEditMode = false;
414448

415449
if (options?.message) {
416450
this._zone.value.widget.value = options?.message;
@@ -449,7 +483,9 @@ export class InteractiveEditorController implements IEditorContribution {
449483
}
450484

451485
if (!this._zone.value.widget.value) {
486+
452487
console.log('before the case when we call WAIT_FOR_INPUT');
488+
453489
return State.WAIT_FOR_INPUT;
454490
}
455491

@@ -479,7 +515,9 @@ export class InteractiveEditorController implements IEditorContribution {
479515
private async [State.MAKE_REQUEST](): Promise<State.APPLY_RESPONSE | State.PAUSE | State.CANCEL | State.ACCEPT> {
480516
assertType(this._editor.hasModel());
481517
assertType(this._activeSession);
518+
482519
console.log('this._activeSession.lastInput : ', this._activeSession.lastInput);
520+
483521
assertType(this._activeSession.lastInput);
484522

485523
const requestCts = new CancellationTokenSource();

0 commit comments

Comments
 (0)