feat: Add select range functionality
- Implement selectRange function in UnofficialEndpoints - Add select_range endpoint to functionRegistry - Import vscode module for text editor operations
This commit is contained in:
parent
af2292c065
commit
01555650ef
@ -1,5 +1,5 @@
|
||||
import { applyCodeWithDiff, applyEditCodeWithDiff } from "../../handler/diffHandler";
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
export namespace UnofficialEndpoints {
|
||||
export async function diffApply(filepath: string, content: string, autoedit: boolean = false) {
|
||||
@ -19,4 +19,33 @@ export namespace UnofficialEndpoints {
|
||||
const res = eval(evalCode);
|
||||
return res;
|
||||
}
|
||||
|
||||
export async function selectRange(fileName: string, startLine: number, startColumn: number, endLine: number, endColumn: number) {
|
||||
let editor = vscode.window.activeTextEditor;
|
||||
|
||||
// If the file is not open or not the active editor, open it
|
||||
if (!editor || editor.document.fileName !== fileName) {
|
||||
const document = await vscode.workspace.openTextDocument(fileName);
|
||||
editor = await vscode.window.showTextDocument(document);
|
||||
}
|
||||
|
||||
if (editor) {
|
||||
if (startLine === -1) {
|
||||
// Cancel selection
|
||||
editor.selection = new vscode.Selection(editor.selection.active, editor.selection.active);
|
||||
} else {
|
||||
// Select range
|
||||
const selection = new vscode.Selection(
|
||||
new vscode.Position(startLine, startColumn),
|
||||
new vscode.Position(endLine, endColumn)
|
||||
);
|
||||
editor.selection = selection;
|
||||
|
||||
// Reveal the selection
|
||||
editor.revealRange(selection, vscode.TextEditorRevealType.InCenter);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -100,6 +100,10 @@ const functionRegistry: any = {
|
||||
"/get_collapsed_code": {
|
||||
keys: ["fileName", "startLine", "endLine"],
|
||||
handler: getCollapsedCode,
|
||||
},
|
||||
"/select_range": {
|
||||
keys: ["fileName", "startLine", "startColumn", "endLine", "endColumn"],
|
||||
handler: UnofficialEndpoints.selectRange,
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user