What are virtual spaces in VirtualSnapshotSpan in the Visual Studio SDK

The Visual Studio 2010 SDK has SnapshotSpans and VirtualSnapshotSpans. According to MSDN, the difference in Virtual Span has virtual spaces, while the other does not.

What is virtual space?

For reference: http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.text.virtualsnapshotspan.aspx

+4
source share
1 answer

Here you can find an explanation:

http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.text.virtualsnapshotpoint%28v=vs.100%29.aspx

Virtual spaces are "extra" spaces at the end of a line that do not add to the line length. You can enable or disable virtual spaces in Visual Studio. When virtual spaces are disabled, pressing the right arrow at the end of the line causes the carriage to move to the beginning of the next line. When virtual spaces are turned on, right-clicking the arrow at the end of the line causes the carriage to move forward on the same line.

Even if the option "Enable virtual space" in the menu "Tools" โ†’ "Options" โ†’ "Text editor" โ†’ "All languages โ€‹โ€‹โ†’" General "is disabled, virtual spaces can be inserted when writing indented text or code.

If you enter input at the end of a line with indentation, Visual Studio adds virtual spaces at the beginning of a new line. These spaces are "virtual" because they have not been entered by the user and will not be saved in a file unless you enter something after the virtual spaces.

This affects the position of the caret: After you press enter at the end of the indent line, the BufferPosition and VirtualBufferPosition properties for CaretPosition will be different. BufferPosition points to column 0 in a new row, and VirtualBufferPosition points to the position at which visualization is rendered.

+5
source

All Articles