Skip custom tagger format when word is inside quotes (").

1 Answer 6 Views
SyntaxEditor
Álvaro
Top achievements
Rank 1
Iron
Iron
Álvaro asked on 29 Apr 2025, 04:55 PM

Hi,

I have develop a custom tagger in order to format some specific words.

My problem is that the format is applying to this words even if they are used as strings (inside quotes).

I would like that the format only applies when the word is not in quotes.

In. Ex:

WORD -> Apply Format

"WORD" -> Do not apply format

 

This is my code:

using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using AutoMapper.Internal;
using Telerik.WinControls.UI;
using Telerik.WinForms.Controls.SyntaxEditor.Taggers;
using Telerik.WinForms.Controls.SyntaxEditor.UI;
using Telerik.WinForms.SyntaxEditor.Core.Tagging;

namespace Simulation.UX.Forms.Controls.Neptune
{
    public class CustomTagger : CSharpTagger
    {
        public static readonly ClassificationType CustomClassificationType = new("Custom");
        public static readonly Dictionary<string, ClassificationType> WordsToClassificationType = new();
        public static readonly TextFormatDefinition Format = new(new SolidBrush(Color.DarkGoldenrod));

        private readonly List<string> _words;

        public NeptuneTagger(RadSyntaxEditorElement editor, List<string> words) : base(editor)
        {
            _words = words;
        }

        protected override Dictionary<string, ClassificationType> GetWordsToClassificationTypes()
        {
            Dictionary<string, ClassificationType> baseTypes = base.GetWordsToClassificationTypes();

            _words?.ForAll(w =>
            {
                if (!baseTypes.ContainsKey(w))
                {
                    baseTypes.Add(w, CustomClassificationType);
                }
            });

            return baseTypes;
        }
    }
}
 

1 Answer, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 30 Apr 2025, 01:16 PM

Hello Álvaro,

I appreciate your interest in our RadSyntaxEditor control for WinForms.

Except for the code in the CustomTagger class, you will need to override the GetTags() method and create custom code that matches the exact word starting index without the quotes. Then you can create a TextSnapshotSpan object, and yield return a TagSpan<ClassificationTag> containing the TextSnapshotSpan and the custom ClassificationType as a parameters.

Currently, we don't have such custom code that demonstrates this requirement. However, you can check the Custom Taggers help article for an example. You can use the code in the article as a starting point. 

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
SyntaxEditor
Asked by
Álvaro
Top achievements
Rank 1
Iron
Iron
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or