Merge pull request #580 from devchat-ai/add_select_range_service
feat: Add select range functionality
This commit is contained in:
commit
ac51fb4cbb
@ -1,5 +1,5 @@
|
|||||||
import { applyCodeWithDiff, applyEditCodeWithDiff } from "../../handler/diffHandler";
|
import { applyCodeWithDiff, applyEditCodeWithDiff } from "../../handler/diffHandler";
|
||||||
|
import * as vscode from 'vscode';
|
||||||
|
|
||||||
export namespace UnofficialEndpoints {
|
export namespace UnofficialEndpoints {
|
||||||
export async function diffApply(filepath: string, content: string, autoedit: boolean = false) {
|
export async function diffApply(filepath: string, content: string, autoedit: boolean = false) {
|
||||||
@ -19,4 +19,33 @@ export namespace UnofficialEndpoints {
|
|||||||
const res = eval(evalCode);
|
const res = eval(evalCode);
|
||||||
return res;
|
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": {
|
"/get_collapsed_code": {
|
||||||
keys: ["fileName", "startLine", "endLine"],
|
keys: ["fileName", "startLine", "endLine"],
|
||||||
handler: getCollapsedCode,
|
handler: getCollapsedCode,
|
||||||
|
},
|
||||||
|
"/select_range": {
|
||||||
|
keys: ["fileName", "startLine", "startColumn", "endLine", "endColumn"],
|
||||||
|
handler: UnofficialEndpoints.selectRange,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user