As mentioned in a previous post, we have been working on refactoring the core internal implementation of our SyntaxEditor code editor control on the WPF, UWP, and WinForms platforms. This effort is being made to bring all three platforms onto the same codebase for easier updating moving forward, and to enhance features wherever possible.
In the previous SyntaxEditor vNext post, we showed some massive improvements in SyntaxEditor touch interaction, including inertia-based touch scrolling and pinch-to-zoom features. In today's post, we'll examine a new feature area that allows you to customize the line numbers displayed in each view's line number margin.
Default Behavior
By default, a view's line number margin displays the line number (document line index plus one) for each view line. If a view line is a wrapped line, nothing appears for that view line in the margin.
In vNext, several new features are being added to support customization of the line number display.
Document Fragment Scenario
One scenario where line number customization is appropriate is when you have an enormous file and only want SyntaxEditor to show a fragment of it, such as several thousand lines. In this scenario, you might make a document with lines 10,000-20,000 in it. The first line in SyntaxEditor is really line 10,000 in the file, but it normally shows as line #1 in the line number margin. This can be confusing to the end user.
A new property on the document class allows you to change the line number origin, which defaults to 1. For the scenario described above, you'd set it to 10,000 instead. All line numbers after that origin number will continue to be relative to it.
Advanced Scenarios
What about cases where a language might have specific line numbers or labels that should show for certain view lines? This is possible too via a new language service that allows for completely customizing the text to display for each view line in the line number margin.
In the screenshot above, we've set the line number margin to show the zero-based offset of each line. For a couple lines, we've also indicated labels for the namespace and class lines.
Summary
The new custom line numbering features are very easy to use for changing default line number margin content.