selection
# selection
与hover
类似,有时候需要处理选中的文本,获取它是通过vscode.TextEditor
实例上的属性,有两个相关属性
selections
:所有被选中的文本信息selection
:第一个被选中的文本信息, 等同于selections[0]
获取TextEditor
的一个方法是通过注册textEditorCommand
,会在回调函数里提供TextEditor
实例,例如展示选中文本:
let command = vscode.commands.registerTextEditorCommand('extension.selection', function(textEditor, edit) {
const text = textEditor.document.getText(textEditor.selection);
console.log('选中的文本是:', text);
});
context.subscriptions.push(command);
1
2
3
4
5
6
2
3
4
5
6
上次更新: 2023/10/17, 16:50:29