The text framework includes an interface for formatting regions of text. Text that has been formatted can be more readable because whitespace and symbols such as braces are uniformly placed.
Formatting Logic
Text formatters implement the IText
The Text
If the IText
When formatting, it is likely that multiple changes will be made. These updates can be batched up into a single undoable text change. For information on text changes, see the Text Changes and Operations topic.
Formatters are free to implement any custom logic to perform the formatting. However, there are most likely going to be similarities in the technique that most formatters use. Here are some common steps that a formatter might follow in the process of formatting a document:
Find the next token that allows whitespace between itself and the following non-whitespace token.
Replace all whitespace between these two tokens with the new whitespace, which can either be no whitespace at all, or a combination of any number of line breaks, tabs and spaces.
Repeat from the first step until the entire range is formatted.
Registering a Text Formatter with a Syntax Language
An IText
Registering a text formatter with a language is optional but recommended.
Formatting a Range of Text
This code uses an ICode0
to 10
:
This code uses an ICode