Final Version. Everything is working; atleast for Python🥳
This commit is contained in:
parent
c1d0a53720
commit
a3bf2f93bb
17
package.json
17
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": [
|
||||
{
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue