microsoft / microsoft/VSExtensibility

SetSelections doesn't change the caret position, it is instead adding additional caret(s) on top of the current one

Open
#409 0 comments 0 reactions 1 assignee View on GitHub

@olegtk is already working on this.

Since Aug 6, 2024.

Dominant language
C#
Stars
440
Forks
63
Avg merge
2d 12h
Merged PRs (30d)
1

Description

When using textview.AsEditable.SetSelections it is adding a new caret selection on top of the current one the editor has.

Repro
The extension command is going to set the caret selection to 5, you can notice the fifth character appears as a blue caret, while the old caret position is still kept (and respected) as the red caret.

https://github.com/user-attachments/assets/f0a1ab8d-300e-4c2f-b666-94a6ce5a8e9f

Code

await Extensibility.Editor().EditAsync(
batch =>
{
    var caret5 = new TextPosition(textView.Document, 5);
    textView.AsEditable(batch).SetSelections([new Selection(activePosition: caret5, anchorPosition: caret5, insertionPosition: caret5)]);
},
cancellationToken);

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.