Home > Mobile >  VSCode Extension: How to set value?
VSCode Extension: How to set value?

Time:12-31

I read through the API doc and understand how to get values, but cannot get well how to set a value.

For example, I wanted to change active line (cursor line) so tried to update the value of editor.selection.active as follows.

// 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}

But as the comments above, it doesn't update the value, doesn't change the active line position. So How can I do this? Thanks.

CodePudding user response:

You have to update the editor.selections property with your new selection:


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


editor.selections = newSelections;
  • Related