Colouring of document lines

SyntaxEditor for WPF Forum

Posted 12 years ago by Dave Haas - Powder Software
Version: 11.2.0553
Avatar

Hi.

I'm building a diff editor for our product and I'm interested in tagging document lines instead of tokens. What would you recommend as a simple solution to tagging lines of the document as one of

  • deleted
  • inserted
  • changed

I'm having a bit of trouble switching from the tokenizing way of doing things to simply tagging (if that's the right term in this case) the lines.

Cheers,

Dave

BTW, if anyone wants it when I'm done I'd be happy to furnish it to your customers, no charge :)

Comments (8)

Answer - Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Dave,

For that sort of thing that isn't inline with the text, you'd want to use a custom adornment layer to render a background for those particular lines.  Check out some of the various adornments QuickStarts since some of them (like the alternating rows one) show how to render various background elements by a line.


Actipro Software Support

Posted 12 years ago by Dave Haas - Powder Software
Avatar

Hi.

I've viewed the alternating row QuickStart and it's not quite what I'm trying to do. In that example the only thing that happens is when the view is drawn every other line is highlighted with the appropriate style. However, for the diff implementation I need to associate information with the document, not the view.

When building the diff implementation what I put in is two arrays of strings (the lines from each document if I'm diffing two files, for example) and what I get out is a list of ranges (unchanged, inserted into the left document or deleted from the right document). What I would then like to be able to do is associate a highlight style with each of those states.

When reading the documentation it sounds like I need to create a custom document tagger that associates my own tag type (one of the 3 states) with the associated range in the document (the line). Then, when the view is painted I get what I want.

Am I on the right track? If so, could you provide some guidance about how to go about that? I've reviewed the HighlightWord Quick Start (for creating custom taggers) but the lifecycle of what to create and where is still a bit fuzzy.

Cheers,

Dave

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

Hi Dave,

It depends what sort of look you are after.  If you are just going to do background highlights behind the actual text characters only (and not extend them all the way to the right side of the control where there might not be characters), then yes, using classification tags (IClassificationTag and a related tagger) will be the easiest way to do this.  The HighlightWord sample is the best one to look for that sort of thing.

Taggers are pull mechanisms, so they are called on-demand as the view goes to render lines.  The one in the HighlightWord sample is dynamically scanning the text in the requested ranges.  If you have stored your diff data in the Document.Properties dictionary then you can retrieve it in the tagger's GetTags method and return tag snapshot ranges as appropriate for the requested range.

Don't forget to register a document tagger provider on your language like this that will create your tagger for each document that is associated with the language:

language.RegisterService(new CodeDocumentTaggerProvider<YourTagger>(typeof(YourTagger)));


Actipro Software Support

Posted 12 years ago by Dave Haas - Powder Software
Avatar

Hmm. That's a good point about the width of the control. The tagger approach would tag the single '\n' that represents either an insert or a delete and that wouldn't work when painting the rest of the line in the view.

Perhaps the Adornment manager is the way to go. I do want the entire line painted appropriately. If I store the diff info in the document properties dictionary then I could look it up when the viewline painting is called (as in the alternating lines quick start).

Thanks for the advice.

Cheers,

Dave

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

Yes, in that case, you'd want to do something similar to the alternating lines QuickStart.  Maybe in the data you store in Document.Properties, you could have a prebuilt data structure that would give you a fast lookup of what special highlight to display giving a particular line index.  Then that would ensure that rendering remains fast.


Actipro Software Support

Posted 12 years ago by Dave Haas - Powder Software
Avatar

On an interesting side note, is it possible to 'skip' lines of the document when painting the view? For example, when diff'ing 2 documents, left and right, suppose there is an 'insert 10 lines' step. Say that 1) the documents are the same up until this point and 2) the 'inserted' lines start at line 50.

That would mean the left document would have 50 lines, 10 'blank' lines that represent the inserted lines into the right document and then would continue on. The right document would have 60 lines ...

It's the 10 'blank' lines in the left document that I want to colour, however I don't really want to insert 10 blank lines into the left document, I just want it to appear that way.

When painting the viewlines would it be possible to add these phantom lines to the view and not the document? It might just be easier to add them to the underlying document, I'm just thinking out loud ...

Cheers,

Posted 12 years ago by Dave Haas - Powder Software
Avatar

Oh, and has the ability to turn off the scroll bars been added yet? I can't find a way to do that yet since I'll be implementing my own ...

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

Hi Dave,

At this time we don't have any way to insert phantom lines or space above a line.  I can add the request to our TODO list.  Inserting blank lines in the document will work best for you.

Sorry but other than single line mode, there isn't a way to turn off scrollbars yet.


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.