Text Buffer Events in the Legacy API

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at Text Buffer Events in the Legacy API.

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.

Following are the interfaces implemented by the text buffer object.

InterfaceDescription
IVsCompoundActionEnables the creation of compound actions (that is, actions that are grouped in a single undo/redo unit).
IVsPersistDocDataEnables persistence of document data managed by the text buffer.
IVsTextBufferProvides basic services; used by many clients.
IVsTextLinesProvides read and write capabilities using two-dimensional coordinates. Inherits from IVsTextBuffer.
IVsTextScannerProvides fast, stream-oriented, sequential access to text in the buffer.
IVsTextStreamProvides read and write capabilities using one-dimensional coordinates. Inherits from IVsTextBuffer.
IVsUserDataProvides 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.
IConnectionPointContainerSupports connection points for events.

Following are the interfaces for text buffer event notification.

InterfaceDescription
IVsTextBufferEventsNotifies clients when a new language service is associated with a text buffer.
IVsTextBufferDataEventsNotifies clients when a text buffer is initialized and when changes are made to data in the text buffer.
IVsTextStreamEventsNotifies clients of changes to the underlying text buffer in one-dimensional coordinates.
IVsTextLinesEventsNotifies clients of changes to the underlying text buffer in two-dimensional coordinates.
IVsUserDataEventsNotifies clients of changes to user data.
IVsPreliminaryTextChangeCommitEventsNotifies 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.
IVsFinalTextChangeCommitEventsNotifies 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.

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

Show: