AdornmentManager's AddAdornment method does not trigger

SyntaxEditor for WPF Forum

Posted 2 years ago by Sunshine - Appeon
Version: 21.1.3
Avatar

I implemented a Tagger by inheriting CollectionTagger<IIntraLineSpacerTag>,and call this.Add() method to add the IIntraLineSpacerTag I implemented.

Then it also implements an IntraLineAdornmentManagerBase<IEditorView, MyIntraLineSpacerTag>.

After I inject them all into Editor.Language, add MyIntraLineSpacerTag through Tagger, AddAdornment in IntraLineAdornmentManager will not trigger.

foreach (ITextViewLine viewLine in e.AddedOrUpdatedViewLines) {
				foreach (TagSnapshotRange<TTag> tagRange in viewLine.GetIntraLineSpacerTags<TTag>()) {
					if ((tagRange.Tag != null) && (tagRange.Tag.Key != null))
						this.AddAdornment(viewLine, tagRange);
				}
			}

I found by looking at the source code that after adding tags, the OnViewTextAreaLayout event will be triggered, but viewLine.GetIntraLineSpacerTags<TTag>() cannot get any tags. I have confirmed that the range of my Tag is within the range of viewLine.

What could cause this situation?

Comments (2)

Posted 2 years ago by Sunshine - Appeon
Avatar

This is part of the code for the tagger.

internal class MyIntraLineSpacerTagger : CollectionTagger<IIntraLineSpacerTag>
    {
        private readonly IEditorView _view;
        public MyIntraLineSpacerTagger(IEditorView view)
            : base(nameof(MyIntraLineSpacerTagger), null, view.SyntaxEditor.Document, true)
        { }
    }

This is part of the code of the decoration manager:

internal class MyIntraLineAdornmentManager
        : IntraLineAdornmentManagerBase<IEditorView, MyIntraLineSpacerTag>
    {
        private static readonly AdornmentLayerDefinition _layerDefinition = new AdornmentLayerDefinition(
            nameof(MyIntraLineAdornmentManager));

        public MyIntraLineAdornmentManager(
            IEditorView view) : base(view, _layerDefinition)
        {
            view.TextAreaLayout += this.OnViewTextAreaLayout;

            view.VisualElement.SizeChanged += this.OnViewSizeChanged;
        }
    }
Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

It's hard to say without a sample to debug with, but I believe that if you inherit IntraLineAdornmentManagerBase, it handles OnViewTextAreaLayout for you and does all the add/translate/remove adornment calls.  All you need to do is override the AddAdornment method, similar to how we do in our AdornmentsIntraLineCodeLens QuickStart.  I'd recommend that you start with that sample and try translating its concepts over to what you are doing.  If you still can't get it working after trying that, please send our support a new simple sample project showing the issue.  Be sure to exclude the bin/obj folders from the .zip you send so it doesn't get spam blocked.  Thanks!


Actipro Software Support

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.