Set cursor programatically at first error position in syntax editor.

SyntaxEditor for WPF Forum

Posted 5 years ago by Ranjit
Version: 17.2.0665
Platform: .NET 4.7
Environment: Windows 10 (64-bit)

we are using the Syntax editor in our application and we have one button called "Validate".

When we click the validate button..i need to set the cursor on the location where the first syntax error is observed.

Comments (4)

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


If you know the zero-based offset from the start of the file of where the syntax error is, you can set the editor.ActiveView.Selection.StartOffset property. Just note that when we load text, we convert \r\n to \n while loaded in our editor for easier parsing, etc. So you may need to adjust the offset to account for the lack of \r characters.

Or if you know the zero-based document line/character combination, you can call document.PositionToOffset(position) to convert that to the offset.

[Modified 5 years ago]

Actipro Software Support

Posted 5 years ago by Ranjit

Thank you for the reply.

Let me put my question in another way..

Currently syntax editor is highlighting the error location with the under line in red color.

If the number of lines in the editor is huge then it is difficult to locate the errors in the script.

From our application, when i click the validate button i should able to position the cursor at the first error position.

using the the syntax editor-wpf ,Is there any way to get the position of first error in the script .

and Is there any way to set the cursor on the same above position

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


Oh I see, you wish to get the range of the syntax errors we are finding in a parser and jump to the first one.  You could do that with this code:

var errorProvider = editor.Document.ParseData as IParseErrorProvider;
if (errorProvider != null) {
	var firstError = errorProvider.Errors.FirstOrDefault();
	if (firstError != null)
		editor.ActiveView.Selection.StartPosition = firstError.PositionRange.FirstPosition;

Actipro Software Support

Posted 4 years ago by Ranjit

Thanks Actipro for your support.

The latest build of this product (v22.1.3) was released 27 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.