Skip to content

Commit e326dbe

Browse files
committed
bug fix: tab command conflict
1 parent 4dcbe22 commit e326dbe

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

packages/amazonq/src/app/inline/EditRendering/displayImage.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6+
import { getLogger, setContext } from 'aws-core-vscode/shared'
67
import { getLogger, setContext } from 'aws-core-vscode/shared'
78
import * as vscode from 'vscode'
89
import { diffLines } from 'diff'
@@ -20,6 +21,7 @@ export class EditDecorationManager {
2021
private currentRemovedCodeDecorations: vscode.DecorationOptions[] = []
2122
private acceptHandler: (() => void) | undefined
2223
private rejectHandler: (() => void) | undefined
24+
private disposables: vscode.Disposable[] = []
2325

2426
constructor() {
2527
this.imageDecorationType = vscode.window.createTextEditorDecorationType({
@@ -29,8 +31,6 @@ export class EditDecorationManager {
2931
this.removedCodeDecorationType = vscode.window.createTextEditorDecorationType({
3032
backgroundColor: 'rgba(255, 0, 0, 0.2)',
3133
})
32-
33-
this.registerCommandHandlers()
3434
}
3535

3636
/**
@@ -137,6 +137,7 @@ export class EditDecorationManager {
137137
originalCodeHighlightRanges: Array<{ line: number; start: number; end: number }>
138138
): void {
139139
// Clear any existing decorations
140+
this.registerCommandHandlers()
140141
this.clearDecorations(editor)
141142

142143
// Set context to enable the Tab key handler
@@ -180,24 +181,30 @@ export class EditDecorationManager {
180181
*/
181182
public registerCommandHandlers(): void {
182183
// Register Tab key handler for accepting suggestion
183-
vscode.commands.registerCommand('aws.amazonq.inline.acceptEdit', () => {
184+
const acceptDisposable = vscode.commands.registerCommand('aws.amazonq.inline.acceptEdit', () => {
184185
if (this.acceptHandler) {
185186
this.acceptHandler()
186187
}
187188
})
189+
this.disposables.push(acceptDisposable)
188190

189191
// Register Esc key handler for rejecting suggestion
190-
vscode.commands.registerCommand('aws.amazonq.inline.rejectEdit', () => {
192+
const rejectDisposable = vscode.commands.registerCommand('aws.amazonq.inline.rejectEdit', () => {
191193
if (this.rejectHandler) {
192194
this.rejectHandler()
193195
}
194196
})
197+
this.disposables.push(rejectDisposable)
195198
}
196199

197200
/**
198201
* Disposes resources
199202
*/
200203
public dispose(): void {
204+
for (const disposable of this.disposables) {
205+
disposable.dispose()
206+
}
207+
this.disposables = []
201208
this.imageDecorationType.dispose()
202209
this.removedCodeDecorationType.dispose()
203210
}
@@ -290,13 +297,22 @@ export async function displaySvgDecoration(
290297
// Handle accept
291298
getLogger().info('Edit suggestion accepted')
292299

300+
// Replace content
301+
302+
// Calculate cursor position before replacing content
303+
const endPosition = getEndOfEditPosition(originalCode, newCode)
304+
293305
// Replace content
294306
replaceEditorContent(editor, newCode)
295307

296308
// Move cursor to end of the actual changed content
297309
const endPosition = getEndOfEditPosition(originalCode, newCode)
298310
editor.selection = new vscode.Selection(endPosition, endPosition)
299311

312+
// Move cursor to end of the actual changed content
313+
editor.selection = new vscode.Selection(endPosition, endPosition)
314+
315+
300316
// Move cursor to end of the actual changed content
301317
editor.selection = new vscode.Selection(endPosition, endPosition)
302318

@@ -315,6 +331,7 @@ export async function displaySvgDecoration(
315331
isInlineEdit: true,
316332
}
317333
languageClient.sendNotification('aws/logInlineCompletionSessionResults', params)
334+
decorationManager.dispose()
318335
},
319336
() => {
320337
// Handle reject
@@ -332,6 +349,7 @@ export async function displaySvgDecoration(
332349
isInlineEdit: true,
333350
}
334351
languageClient.sendNotification('aws/logInlineCompletionSessionResults', params)
352+
decorationManager.dispose()
335353
},
336354
originalCode,
337355
newCode,

0 commit comments

Comments
 (0)