0

I am writing some unit test method to check some functionality after user selects a particular characters within the .cs file/.

So for this, I have created dte object & set its Active Document to my abc.cs file & want to programmatically select a few characters within a line in that abc.cs file.

((TextSelection)m_testHelper.Dte2.ActiveDocument.Selection).GotoLine(46,true);

This allows to select the whole line(no. 46 in abc .cs file). But I want the text in quotes to be set for Selection as below shown in abc .cs file at Line no. 46

private const string HeartBeatFileName = "abc.exe.heartbeat";

Also tried:

((TextSelection)m_testHelper.Dte2.ActiveDocument.Selection).MoveToLineAndOffset(46, 50, true);

But nt working as expected. Am I doing something wrong??

Deepthi
  • 41
  • 1
  • 7

1 Answers1

0

You need first to move to the initial point without extending the selection and then to move to the final point extending the selection. This sample selects the characters 5 to 10 of the first line of the active document:

EnvDTE.TextSelection textSelection;

textSelection = (EnvDTE.TextSelection) _dte.ActiveDocument.Selection;

textSelection.MoveToLineAndOffset(1, 5, false);
textSelection.MoveToLineAndOffset(1, 10, true);
Carlos Quintero
  • 4,300
  • 1
  • 11
  • 18