diff --git a/package.json b/package.json index bf85831..a3c4aef 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "displayName": "Fabelous Autocoder", "description": "A simple to use Ollama autocompletion Plugin", "icon": "icon.png", - "publisher": "fabel", + "publisher": "Falko Habel", "license": "CC BY-ND 4.0", "bugs": { "url": "https://gitea.fabelous.app/fabel/Fabelous-Autocoder/issues" @@ -114,11 +114,16 @@ } }, "keybindings": [ - { - "command": "fabelous-autocoder.handleTab", - "key": "tab", - "when": "editorTextFocus && !editorTabMovesFocus" - } + { + "command": "fabelous-autocoder.handleTab", + "key": "tab", + "when": "editorTextFocus && !editorTabMovesFocus" + }, + { + "command": "fabelous-autocoder.handleBackspace", + "key": "backspace", + "when": "editorTextFocus" + } ], "commands": [ { diff --git a/src/extension.ts b/src/extension.ts index 1026b12..0bbacc8 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -144,31 +144,39 @@ class CompletionManager { const edit = new vscode.WorkspaceEdit(); const completionLines = this.completionText.split('\n'); const numberOfLines = completionLines.length; - + // Ensure the start position is never negative const safeStartPosition = new vscode.Position(Math.max(0, this.startPosition.line - 1), 0); - + // Prepare the range to replace const rangeToReplace = new vscode.Range( safeStartPosition, this.startPosition.translate(numberOfLines, 0) ); - + // Construct the content to insert const contentToInsert = (safeStartPosition.line === 0 ? '' : '\n') + this.completionText + '\n'; edit.replace(this.document.uri, rangeToReplace, contentToInsert); - + await vscode.workspace.applyEdit(edit); - this.clearPreview(); // Clear the preview decorations - + + // Clear the preview decorations + this.clearPreview(); + + // Set activeCompletionManager to null + activeCompletionManager = null; + // Calculate the new cursor position from the inserted content const lastCompletionLine = completionLines[completionLines.length - 1]; - const newPosition = new vscode.Position(this.startPosition.line + numberOfLines - 1, lastCompletionLine.length); - - // Set the new cursor position without any additional move + const newPosition = new vscode.Position( + this.startPosition.line + numberOfLines - 1, + lastCompletionLine.length + ); + + // Set the new cursor position this.textEditor.selection = new vscode.Selection(newPosition, newPosition); } - + public clearPreview() { @@ -204,6 +212,7 @@ class CompletionManager { this.textEditor.selection = new vscode.Selection(this.startPosition, this.startPosition); console.log(`Lines ${startLine + 1} to ${endLine + 1} removed successfully`); + activeCompletionManager = null; } else { console.log('No lines to remove'); }