From VS2008 VSPackage, how do I get notified when the carriage position has changed?

I would like to receive notifications when the caret position has changed in the active text view. The only thing EnvDTE offers is the LineChanged event , which, of course, does not rise when the cursor moves left or right within the same line.

I understand that VS2010 Editor Extensibility allows you to do this without sweat, but I need a solution that is backward compatible with VS2008.

+6
source share
2 answers

I have found a solution. The solution is to create an IOleCommandTarget and register it on IVsTextView (see the last two bits of code in this blog post (in Hebrew) ). Then every time the command is run, I check to see if the caret position has changed. See Also: This Blog Post - How to Intercept Key Presses in a Visual Studio Text Editor

0
source

You saw this: DTE2 events do not fire

You must save the local instance of the Events object, otherwise the event will not fire (I assume that the COM-enabled COM object went out of scope and was GC'd):

public class MyVSPackage { TextEditorEvents _textEditorEvents; public MyVSPackage() { _textEditorEvents = DTE.Events.TextEditorEvents; _textEditorEvents.LineChanged += (point, endPoint, hint) => //Do something here } } 
+1
source

Source: https://habr.com/ru/post/945039/


All Articles