简体   繁体   中英

How to get the character to the left of cursor in Visual Studio Extension?

I'm trying to get the character on the left of cursor. I've got the handler that intercepts the LineChanged event.

OnLineChanged(TextPoint startPoint, TextPoint endPoint, int Hint)

I couldn't find any built in method to get that from TextPoint s.

What's the best way to do that?

Also, is there a way to check if the active window has IntelliSense window open? I want to abort the event handler execution if IntelliSense is open.

To get the character to the left of the EnvDTE.TextPoint:

string CharacterToTheLeft(EnvDTE.TextPoint p)
{
    EnvDTE.EditPoint editPoint = p.CreateEditPoint();
    editPoint.CharLeft();
    return editPoint.GetText(1);
}

To create an edit point at the current cursor position from EnvDTE.TextPoint startPoint:

    EnvDTE.TextSelection ts = startPoint.Parent.Selection;
    EnvDTE.EditPoint editPoint = ts.ActivePoint.CreateEditPoint();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM