Udostępnij za pośrednictwem


Accessing the Text Buffer by Using 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 is responsible for managing text streams and file persistence. Although the buffer can read or write other formats, all ordinary communication with the buffer is performed by using Unicode. In the legacy APIs, the text buffer can use either a one- or a two-dimensional coordinate system to identify character locations in the buffer.

One- and Two-Dimension Coordinate Systems

A one-dimensional coordinate position is based on a character's position from the first character in the buffer, such as 147. You use the IVsTextStream interface to access a one-dimensional location in the buffer. A two-dimensional coordinate system is based on line and index pairs. For example, a character in the buffer at 43, 5 would be on line 43, five characters to the right of the first character in that line. You access a two-dimensional location in the buffer using the IVsTextLines interface. Both the IVsTextLines and the IVsTextStream interfaces are implemented by the text buffer object (VsTextBuffer) and can be accessed from each other by using QueryInterface. The following diagram shows these and other key interfaces on VsTextBuffer.

Text Buffer Object
Text buffer object

Although either coordinate system works in the text buffer, it is optimized to use two-dimensional coordinates. A one-dimensional coordinate system can create performance overhead. Therefore, use the two-dimensional coordinate system whenever possible.

The text buffer's second responsibility is file persistence. To do this, the text buffer object implements IVsPersistDocData2 and acts as the document data object component for project items and other environment components involved in persistence. For more information, see Opening and Saving Project Items.

In This Section

Changing View Settings by Using the Legacy API
Explains how to change view settings using the legacy API.

Using the Text Manager to Monitor Global Settings
Explains how to use the text manager to monitor global settings..

See Also

Inside the Core Editor