Reputation: 451
I am maintaining a VSIX and I try to select the word at cursor with the DTE
I have this function so far, and although it does select the word at cursor, the selection is dimmed. I mean it does not look like a mouse selection, you can barely see it
I expect the selection to be like "done with the mouse" and not dimmed down
public static void SelectWordAtCursor()
{
Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();
Document doc = Distributor.m_dte.ActiveDocument;
if (doc == null)
throw new Exception("No open document found");
TextSelection selection = (TextSelection)doc.Selection;
if (selection == null)
throw new Exception("No selection found");
// Move the cursor to the beginning of the word
selection.WordLeft();
int startOffset = selection.AnchorPoint.AbsoluteCharOffset;
// Move the cursor to the end of the word
selection.WordRight();
int endOffset = selection.ActivePoint.AbsoluteCharOffset;
// Set the selection to the word
selection.MoveToAbsoluteOffset(startOffset);
selection.MoveToAbsoluteOffset(endOffset,true);
}
This is selected by the code above
This is selected with the mouse
Thanks for your help on this
Upvotes: 0
Views: 29