Simple squiggle example with arbitrary offsets.

SyntaxEditor for WPF Forum

Posted 4 years ago by James Kester - Metafile Information Systems, Inc.
Version: 20.1.0400

Hello, I have a collection of errors, with offsets. I would like to add squiggles to my editor based on the offsets of the errors in my collection. I have been looking at the quick starts but I am having trouble getting anything to work. I would like to just new up a Squiggle tag and apply it to the editor. Do you have a simple example of how to add arbitrary squiggles based on offsets?


Comments (1)

Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA

Hi James,

We've had some other customers ask this too, so we're going to modify the Adornments Squiggles Intro QuickStart for the next maintenance release.  If you want to change it now, you can do these steps:

First, in CustomSquiggleTagger, change it to inherit CollectionTagger<ISquiggleTag> instead and remove the existing GetTags method.

Second, add this service registration to CustomSyntaxLanguage so quick info can show for the tags:

// Register a squiggle tag quick info provider
this.RegisterService(new SquiggleTagQuickInfoProvider());

Finally, add some code-behind to MainControl.xaml and add a constructor call to this new method after InitializeComponent:

/// <summary>
/// Rescan the document and look for instances of the word 'Actipro' to mark with squiggle tags.
/// </summary>
private void RefreshSquiggleTags() {
	// Get the tagger that was created by the language and has been persisted in the document's properties
	//   while the language is active on the document
	CustomSquiggleTagger tagger = null;
	if (editor.Document.Properties.TryGetValue(typeof(CustomSquiggleTagger), out tagger)) {
		using (var batch = tagger.CreateBatch()) {
			// Clear existing tags

			// Look for regex pattern matches
			var snapshot = editor.ActiveView.CurrentSnapshot;
			var matches = Regex.Matches(snapshot.GetText(LineTerminator.Newline), @"\bActipro\b", RegexOptions.IgnoreCase);
			for (var matchIndex = 0; matchIndex < matches.Count; matchIndex++) {
				var match = matches[matchIndex];

				// Create a version range for the match
				var snapshotRange = new TextSnapshotRange(snapshot, TextRange.FromSpan(match.Index, match.Length));
				var versionRange = snapshotRange.ToVersionRange(TextRangeTrackingModes.DeleteWhenZeroLength);
				// Create a tag, and include a quick info tip if specified
				var tag = new SquiggleTag();
				tag.ClassificationType = ClassificationTypes.Warning;
				tag.ContentProvider = new PlainTextContentProvider(String.Format("Instance number {0}", matchIndex + 1));

				// Add the tag to the tagger
				tagger.Add(new TagVersionRange<ISquiggleTag>(versionRange, tag));


After that, you should be able to open the sample and still see the text Actipro marked with squiggles.  Mouse hover over the squiggles to see related quick info.

In a production app, you wouldn't generally want to get the full snapshot text like we do here since that can affect performance if done for a large document in the UI thread.  But you can see in this example how any collection of text ranges (like those from some some external error scan) can be tagged with squiggles.

Actipro Software Support

The latest build of this product (v24.1.2) 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.