From a3bf2f93bbe9941f930af28c087554397be37b17 Mon Sep 17 00:00:00 2001 From: Falko Habel Date: Wed, 9 Oct 2024 19:58:21 +0200 Subject: [PATCH] =?UTF-8?q?Final=20Version.=20Everything=20is=20working;?= =?UTF-8?q?=20atleast=20for=20Python=F0=9F=A5=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 17 +++++++++++------ src/extension.ts | 29 +++++++++++++++++++---------- 2 files changed, 30 insertions(+), 16 deletions(-) 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'); }