Highlighting a line like the current one

SyntaxEditor for WPF Forum

Posted 8 months ago by Daniel Constantin - ModuleWorks GmbH
Version: 19.1.0687
Avatar

Hi,

I want to highlight some line given the line index in the same way as the current line is highlighted (SyntaxEditor.IsCurrentLineHighlightingEnabled) . I want to highlight it with a red border.

Kind regards,

Daniel

Comments (5)

Answer - Posted 8 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Daniel,

I did a quick test where I started with the AdornmentsCustomDecorator QuickStart sample.  I changed the AddAdornment method to the following and removed the CreateDecorator method:

protected override void AddAdornment(AdornmentChangeReason reason, ITextViewLine viewLine, TagSnapshotRange<CustomTag> tagRange, TextBounds bounds) {
	this.AdornmentLayer.AddAdornment(reason, OnDrawAdornment, viewLine.Bounds, null, viewLine, tagRange.SnapshotRange, TextRangeTrackingModes.LineBased, null);
}

Then I added this method to draw the rectangle:

private void OnDrawAdornment(TextViewDrawContext context, IAdornment adornment) {
	var color = Color.FromArgb(0xff, 0xff, 0x00, 0x00);
			
	var bounds = adornment.ViewLine.Bounds;
	bounds.X = context.TextAreaBounds.X;
	bounds.Width = context.TextAreaBounds.Width;

	context.DrawRectangle(bounds, color, LineKind.Solid, 1);
}

The resulting sample shows how any line with the word "Actipro" on it will be rendered with a red border around the entire view line.

That sample's tagger is dynamically examining tags for the word "Actipro".  You'd probably want to use a CollectionTagger instead, like in the AdornmentsIntraTextNotes QuickStart.


Actipro Software Support

Posted 8 months ago by Daniel Constantin - ModuleWorks GmbH
Avatar

Hi,

I want to make the line which is executed at that moment more like in Visual Studio. So I know the index of the executed line. There is that yellow arrow on the left side, and the text is selected. I want the same behavior, but for the text maybe to have a red border.

Kind regards,

Daniel

Posted 8 months ago by Daniel Constantin - ModuleWorks GmbH
Avatar

I want to know if I can bassically change the style for a current statement indicator :) The existing one is good enough if this is not possible.

The glyph is ok but I would like to put a colored border around the entire line.

Kind regards,

Daniel

Posted 8 months ago by Daniel Constantin - ModuleWorks GmbH
Avatar

Also I want to be able to add a breakpoint when double clicking the indicator margin. Is this possible ?

Answer - Posted 8 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Daniel,

If you want to customize the current line indicator style to include a border, you could do something like this:

var displayClassificationTypes = new DisplayItemClassificationTypeProvider();
displayClassificationTypes.RegisterAll();
var style = AmbientHighlightingStyleRegistry.Instance[displayClassificationTypes.CurrentStatement];
style.BorderColor = Colors.Red;
style.BorderKind = LineKind.Solid;

Also the event sink class in the IndicatorsDebugging QuickStart shows you how to handle a click in the indicator margin to toggle a breakpoint.  Note that that example is showing a single click to toggle, like in Visual Studio's editor. 

To do a double-click instead, you could track where a button press was made and the click's date/time, and then look at a second pressed event's pointer location and date/time and ensure they are within a valid double-click range (i.e. within a few pixels max, and a number of milliseconds apart).


Actipro Software Support

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