Set cursor programatically at first error position in syntax editor.

SyntaxEditor for WPF Forum

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

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 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

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 6 years ago]


Actipro Software Support

Posted 6 years ago by Ranjit
Avatar

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 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

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 6 years ago by Ranjit
Avatar

Thanks Actipro for your support.

The latest build of this product (v24.1.2) was released 1 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.