Compartilhar via


Text Buffer Events in the Legacy API

Note

This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

The text buffer object emits several different events that allow you to respond to different situations.

When you are using the legacy API, you should implement the following interfaces in order to receive notification of changes to the text buffer. Expose the interfaces to the text buffer using the IConnectionPointContainer interface on the text buffer to receive notification of line changes from the buffer. For more information, see How to: Register for Text Buffer Events with the Legacy API. In the case of IVsTextStreamEvents or IVsTextLinesEvents interfaces, changes are returned in either one- or two-dimensional coordinates, respectively.

Text Buffer Interfaces

Following are the interfaces implemented by the text buffer object.

Interface Description
IVsCompoundAction Enables the creation of compound actions (that is, actions that are grouped in a single undo/redo unit).
IVsPersistDocData Enables persistence of document data managed by the text buffer.
IVsTextBuffer Provides basic services; used by many clients.
IVsTextLines Provides read and write capabilities using two-dimensional coordinates. Inherits from IVsTextBuffer.
IVsTextScanner Provides fast, stream-oriented, sequential access to text in the buffer.
IVsTextStream Provides read and write capabilities using one-dimensional coordinates. Inherits from IVsTextBuffer.
IVsUserData Provides access to a generic collection of properties. The most important property is the name, or moniker, of the buffer. You can store your own random data in the buffer with this interface by creating a GUID and using it as a key.
IConnectionPointContainer Supports connection points for events.

Text Buffer Event Interfaces

Following are the interfaces for text buffer event notification.

Interface Description
IVsTextBufferEvents Notifies clients when a new language service is associated with a text buffer.
IVsTextBufferDataEvents Notifies clients when a text buffer is initialized and when changes are made to data in the text buffer.
IVsTextStreamEvents Notifies clients of changes to the underlying text buffer in one-dimensional coordinates.
IVsTextLinesEvents Notifies clients of changes to the underlying text buffer in two-dimensional coordinates.
IVsUserDataEvents Notifies clients of changes to user data.
IVsPreliminaryTextChangeCommitEvents Notifies clients of the last commit gesture to trigger the event and provides the range of text changed. The IVsPreliminaryTextChangeCommitEvents interface is not fired in response to Undo or Redo commands. Events only fire for buffers that have an undo manager. IVsPreliminaryTextChangeCommitEvents is fired prior to other events, such as pretty listing, in order to make sure the other events do not alter the text before the changes are committed. Your VSPackage must monitor either the IVsPreliminaryTextChangeCommitEvents interface or the IVsFinalTextChangeCommitEvents interface, but not both.
IVsFinalTextChangeCommitEvents Notifies clients of the last commit gesture to trigger the event and provides the range of text changed. The IVsFinalTextChangeCommitEvents interface is not fired in response to Undo or Redo commands. Events only fire for buffers that have an undo manager. IVsFinalTextChangeCommitEvents is intended for use only by language services or other objects that have complete control over editing. Your VSPackage must monitor either the IVsPreliminaryTextChangeCommitEvents interface or the IVsFinalTextChangeCommitEvents interface, but not both.

See Also

Accessing the Text Buffer by Using the Legacy API
How to: Register for Text Buffer Events with the Legacy API