lmc*_*iro 5 typescript visual-studio-code vscode-extensions
我在扩展中有一个命令,在运行该命令之前,我想更改选择范围以获取整行...
const sel = textEditor.selection;
const firstLine = textEditor.document.lineAt(sel.start.line);
const lastLine = textEditor.document.lineAt(sel.end.line);
const range = new vscode.Range(firstLine.lineNumber, firstLine.range.start.character, lastLine.lineNumber, lastLine.range.end.character);
Run Code Online (Sandbox Code Playgroud)
我创建了一个新范围,但我不知道如何将文档的选择设置为新范围...
new Selection()有 2 个重载(2 或 4 个参数):
Selection(anchor: vscode.Position, active: vscode.Position)Selection(anchorLine: number, anchorCharacter: number, activeLine: number, activeCharacter: number)例如,使用 4 个参数:
textEditor.selection = new vscode.Selection(firstLine.lineNumber, firstLine.range.start.character,
lastLine.lineNumber, lastLine.range.end.character)
Run Code Online (Sandbox Code Playgroud)
要制作多个光标,您需要设置textEditor.selections
textEditor.selection = new vscode.Selection(firstLine.lineNumber, firstLine.range.start.character,
lastLine.lineNumber, lastLine.range.end.character)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3203 次 |
| 最近记录: |