Search code examples
c#.netwpfvisual-studio-2010mef

What are Virtual Spaces in a VirtualSnapshotSpan in the Visual Studio SDK


In the Visual Studio 2010 SDK there is SnapshotSpans and VirtualSnapshotSpans. According to MSDN, the difference is the Virtual Span has Virtual Spaces, the other does not.

What exactly is a Virtual Space?

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


Solution

  • You can find an explanation here:

    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 length of the line. You can enable or disable virtual spaces in Visual Studio. When virtual spaces are disabled, pressing on the right arrow key at the end of a line causes the caret to move to the beginning of the next line. When virtual spaces are enabled, pressing on the right arrow key at the end of a line causes the caret to move forward on the same line.

    Even if the option “Enable virtual Space” under Tools -> Options -> Text Editor -> All Languages -> General is disabled, virtual spaces can be inserted when writing indented text or code.

    If you type enter at the end of an indented line, Visual Studio adds virtual spaces at the beginning of the new line. These spaces are "virtual" since they have not been typed by the user and will not be saved in the file unless you enter something after the virtual spaces.

    This affects the position of the caret: After pressing enter at the end of an indented line the "BufferPosition"- and "VirtualBufferPosition"-properties of CaretPosition will be different. BufferPosition points to column 0 in the new line and VirtualBufferPosition points to the position where the caret is visually rendered.