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);
© 2017~ 随风逐叶 all right reserved,powered by Gitbook文章修订时间: 2021-10-20 16:12:06

results matching ""

    No results matching ""