Need help with selection issue

SyntaxEditor for WPF Forum

Posted 13 years ago by SledgeHammer01
Version: 11.1.0545
Avatar
Hi,

I'm trying to implement a Find / Replace dialog box on top of the syntax editor. The core functionality is in, but I can't seem to be able to select the correct text consistently.

To find the text, I do this:
_nStartPos = _syntaxEditor.Text.IndexOf(tbSearch.Text, _nStartPos, ((bool)cbMatchCase.IsChecked) ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase);

nLen = tbSearch.Text.Length;


To highlight the text, I do this:
_syntaxEditor.ActiveView.Selection.SelectRange(_nStartPos, nLen);
This is usually WAY off the further I go down in the document. The text contains \r\n's obviously as well as \t's. I figured that was throwing things off so I tried doing a replace:

\r\n -> ""
\t -> " " (four spaces)

and using that to find the IndexOf, but that didn't work either. Any suggestions?

[Modified at 08/22/2011 12:19 PM]

Comments (1)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Internally we strip the \r characters so \n is only used for line ends. The Text property restores \r\n.

Your best bet is to use our snapshot searching API (see the documentation topic "Text/Parsing Framework - Advanced Text Features / Low-Level Search Operations"), or if you don't want to use those methods, you can get the text with \n ends like:
_syntaxEditor.Document.CurrentSnapshot.GetText(LineTerminator.Newline);


Actipro Software Support

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

Add Comment

Please log in to a validated account to post comments.