Share via


Text Buffer for the Visual Studio Editor

The role of the text buffer in the integrated development environment (IDE) is to manage the stream of Unicode text that is entered into the editor and to manage file persistence, or saving text files. Although the buffer can read or write other formats, all ordinary communication with the buffer is performed by using Unicode. The text buffer can use either a one- or 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 secondary role in the IDE 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.

See Also

Other Resources

Core Editor