It would be good too see if it's either a tab or many spaces that are used in the code.
1 Answer, 1 is accepted
0
Stenly
Telerik team
answered on 15 Aug 2022, 11:08 AM
Hello Mattias,
To show the whitespaces, you could highlight them using a custom tagger. An example of this can be found in the Taggers example from our Demos application.
The following code snippet shows a sample implementation of this tagger:
publicclassCustomTextHighlightTagger : TaggerBase<TextHighlightTag>
{
publicstaticreadonly ITextFormatDefinitionKey CustomHighlightDefinition =
new TextFormatDefinitionKey("CustomHighlightDefinition");
private ITextFormatDefinitionKey formatDefinitionKey;
privatestring searchWord;
publicCustomTextHighlightTagger(RadSyntaxEditor editor, ITextFormatDefinitionKey definitionKey, string searchWord)
: base(editor)
{
this.formatDefinitionKey = definitionKey;
this.searchWord = searchWord;
editor.TextFormatDefinitions.AddLast("CustomHighlightDefinition", new TextFormatDefinition(new Telerik.Windows.Controls.SyntaxEditor.UI.Pen(Brushes.Orange, 1)));
}
publicoverride IEnumerable<TagSpan<TextHighlightTag>> GetTags(NormalizedSnapshotSpanCollection spans)
{
if (string.IsNullOrEmpty(this.searchWord))
{
yieldbreak;
}
TextSnapshot snapshot = this.Document.CurrentSnapshot;
foreach (TextSnapshotSpan snapshotSpan in spans)
{
string lineString = snapshotSpan.GetText();
int index = lineString.IndexOf(this.searchWord);
while (index != -1)
{
TextSnapshotSpan tempSnapshotSpan = new TextSnapshotSpan(snapshot,
new Telerik.Windows.SyntaxEditor.Core.Text.Span(snapshotSpan.Start + index, searchWord.Length));
yieldreturnnewTagSpan<TextHighlightTag>(tempSnapshotSpan, new TextHighlightTag(this.formatDefinitionKey));
index = lineString.IndexOf(this.searchWord, index + this.searchWord.Length);
}
}
}
}
Registering the custom tagger in the RadSyntaxEditor instance:
var whitespaceHighlightsTagger = new CustomTextHighlightTagger(this.syntaxEditor, CustomTextHighlightTagger.CustomHighlightDefinition, " ");
this.syntaxEditor.TaggersRegistry.RegisterTagger(whitespaceHighlightsTagger);
The produced result:
Regarding the highlighting of a tabulation, I have tried incorporating this functionality, while keeping the above logic about the whitespaces, however, I was unsuccessful.
Could you give this suggestion a try?
Regards,
Stenly
Progress Telerik
The Premier Dev Conference is back!
Coming to you live from Progress360 in-person or on your own time, DevReach for all. Register Today.