IVsLanguageTextOps::Format Method (IVsTextLayer^, array<TextSpan>^)
Formats the selected text.
Assembly: Microsoft.VisualStudio.TextManager.Interop (in Microsoft.VisualStudio.TextManager.Interop.dll)
Parameters
- pTextLayer
-
Type:
Microsoft.VisualStudio.TextManager.Interop::IVsTextLayer^
[in] An IVsTextLayer object containing the text to format.
- ptsSel
-
Type:
array<Microsoft.VisualStudio.TextManager.Interop::TextSpan>^
[in] Text span to format within the specified layer. For more information, see TextSpan.
Return Value
Type: System::Int32If the method succeeds, it returns S_OK. If it fails, it returns an error code.
From textmgr.idl:
HRESULT IVsLanguageTextOps::Format( [in] IVsTextLayer *pTextLayer, [in] const TextSpan *ptsSel );
This function is called when the user selects Format Document or Format Selection from the Edit -> Advanced menu, and requests that the language service provide formatting for the referenced text span. Formatting typically means to adjusting line indenting, adding spaces after commas, or even moving braces to a new line with proper indentation.
This method can also be called whenever the user types a character that can trigger a reformat (what that character is depends on the language service but typically it is a closing brace or semicolon).
Note |
|---|
It is strongly recommended that if you implement this method, you wrap all changes made to the document in an IVsCompoundAction object so the user can undo the entire format operation in one action. |
