【问题标题】:VSCode Extension: How to set value?VSCode 扩展:如何设置值?
【发布时间】:2021-12-30 15:48:50
【问题描述】:

我通读了 API 文档并了解如何获取值,但不知道如何设置值。

例如,我想改变活动行(光标线)所以尝试更新editor.selection.active的值如下。

// get the current value
editor.selection.active
V {_line: 12, _character: 0}

// I tried to update the value
editor.selection.active.line = 3
3

// I was expecting this an updated value but unchanged
editor.selection.active
V {_line: 12, _character: 0}

但是和上面的 cmets 一样,它不会更新值,也不会改变活动行的位置。那么我该怎么做呢?谢谢。

【问题讨论】:

  • 用于选择更新:使用您想要的选择创建一个新数组并将此数组分配给editor.selections

标签: visual-studio-code vscode-extensions


【解决方案1】:

您必须使用您的新选择更新 editor.selections 属性:


const newStartPosition = new vscode.Position(3, 0);
const newEndPosition = new vscode.Position(yourLine, yourCharacter);
const newSelections = [new vscode.Selection(newStartPosition, newEndPosition )];


editor.selections = newSelections;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-02-10
    • 2022-11-17
    • 2017-06-29
    • 1970-01-01
    • 1970-01-01
    • 2021-11-02
    • 1970-01-01
    • 2016-06-14
    相关资源
    最近更新 更多