WPF SyntaxEditor how to place the caret at specified position?

SyntaxEditor for WPF Forum

Posted 5 years ago by Murali Mahendra Kumar Banala
Version: 19.1.0681
Avatar

Hi 

I have just upgraded the code from version v16.1.0631 to the v19.1.0681 and found that I'm unable to set the caret position of the syntaxEditor to specified location. Here was my earlier code:

IEditorView view = this.syntaxEditor.ActiveView;
view.SyntaxEditor.Caret.Position = new TextPosition(lineNumber, 0);

Now I see that Caret property is not available, how to set the caret position to the desired line number and location?

Thanks in advance

Comments (4)

Posted 5 years ago by Murali Mahendra Kumar Banala
Avatar

Okay found that it can achieved through

syntaxEditor.ActiveView.Selection

syntaxEditor.ActiveView.Selection.CaretPosition = new TextPosition(lineNumber - 1, 0);

Hope this is correct way of implementation.

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

Hello,

Yes that is correct.  We made some breaking changes in 2019.1, but documented all of them.  Please see the "SyntaxEditor / Converting from Previous Versions / Converting to 2019.1" topic in the documentation that comes with the product.  That walks through everything that was changed.


Actipro Software Support

Posted 4 years ago by Amit khurana
Avatar

Above solution will go to first position of that line. But let say i have line "There is testing for actiprosoftware". I put caret through UI in between "actipro" and "software". So, how to identity position. As per current syntaxeditor.caret.position contains Line and character. Line means zero index current line number and character means how many characters in current line. If i want to give space between actiprosoftware or any text. I couldn't current caret position.

[Modified 4 years ago]

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

As of the 2019.1 version where we added multiple carets/selections, the "syntaxEditor.Caret.Position" call is now "syntaxEditor.ActiveView.Selection.CaretPosition".  That returns a TextPosition, which is a line/character pair.

If you want the zero-based offset related to the document start, then that is "syntaxEditor.ActiveView.Selection.CaretOffset". 


Actipro Software Support

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

Add Comment

Please log in to a validated account to post comments.