Search code examples
c#visual-studio-2008vsxenvdte

From a VS2008 VSPackage, how do I get notified whenever caret position changed?


I'd like to get notified whenever the caret position changed in the active text view. The only thing EnvDTE seems to offer is the LineChanged event, which of-course does not get raised when moving the caret left or right within the same line.

I realize VS2010's Editor Extensibility lets you do this with no sweat, but I need a solution that is backwards compatible with VS2008.


Solution

  • I found a solution. The solution is to create an IOleCommandTarget and register it on the IVsTextView (See the last two bits of code in this blog post (in Herbrew)). Then, each time a command is fired, I check whether the caret position has changed. See also: this blog post - How to intercept key presses in the Visual Studio text editor