Hi Actipro,
I am not sure if this is the same problem as this. I am seeing the problem with Build 2015.1.624.
If I have the following sample text:
string sampleText =
@"The quick brown fox jumped over the lazy dog.
This is another line.
The quick brown dog jumped over the lazy fox.
This is some other lines.
This is also another line.
This is yet another line.
";
Problem #1:
If I place my cursor at "This is yet anothe~r line." where ~ is the caret position, When I perform a search up, I am getting the text "another" from that line itself.
My expected behavior is to be same with how Visual Studio has it. Visual Studio would return the "another" from the line before that "This is also another line."
With the word selected, the search up works okay. That is, if I have "This is yet [another] line." where [] is my selection. The search up can find me the correct text from one line before last.
Problem #2:
I am observing different result in searching up when using FindNext with and without TextRange defined.
// Problematic Search up.
ISearchResultSet searchResultSet = snapshot.FindNext(searchOptions, startOffset, false, txtRange);
// OK Search Up.
ISearchResultSet searchResultSet = snapshot.FindNext(searchOptions, startOffset, false);
Here is my complete code (modified from SvenG's unit test):
using ActiproSoftware.Text;
using ActiproSoftware.Text.Implementation;
using ActiproSoftware.Text.Searching;
using ActiproSoftware.Windows.Controls.SyntaxEditor;
using ActiproSoftware.Windows.Controls.SyntaxEditor.Implementation;
using System.Linq;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
#region Arrange
const string searchString = "another";
const bool searchUp = true;
ITextSnapshot snapshot = GetSampleTextSnapshot();
// With no text range: 5,12 gets the 6th Line "This is yet [another] line.
// 5,11 gets the 5th Line "This is also [another] line."
// With text range: 5,12 gets no result.
// 5,11 gets the Line 5th "This is also [another] line."
// Expected: 5,18 i.e. "This is yet anothe~r line" should get the result of "This is also [another] line."
TextPosition startPos = new TextPosition(5,12);
TextPosition endPos = new TextPosition(0,0);
int startOffset = snapshot.PositionToOffset(startPos);
int endOffset = snapshot.PositionToOffset(endPos);
TextRange txtRange = new TextRange(startOffset, endOffset);
int line = snapshot.OffsetToPosition(startOffset).Line;
string snapString = snapshot.Lines[line].Text;
ISearchOptions searchOptions = GetSearchOptionsFromSearchSettings(searchString, searchUp);
#endregion
#region Act
ISearchResultSet searchResultSet = snapshot.FindNext(searchOptions, startOffset, false, txtRange);
#endregion
#region Assert
ISearchCapture firstCapture = searchResultSet.Results.First().Captures.First();
TextPosition resultLine = snapshot.OffsetToPosition(firstCapture.TextRange.StartOffset);
#endregion
}
private static ITextSnapshot GetSampleTextSnapshot()
{
string sampleText =
@"The quick brown fox jumped over the lazy dog.
This is another line.
The quick brown dog jumped over the lazy fox.
This is some other lines.
This is also another line.
This is yet another line.
";
CodeDocument document = new CodeDocument();
document.SetText(sampleText);
return document.CurrentSnapshot;
}
private static ISearchOptions GetSearchOptionsFromSearchSettings(string text, bool searchUp, int maximumResultCount = 1)
{
return new EditorSearchOptions
{
FindText = text,
MatchCase = false,
MatchWholeWord = false,
SearchUp = searchUp,
PatternProvider = SearchPatternProviders.Normal,
Scope = EditorSearchScope.Document,
MaximumResultCount = maximumResultCount
};
}
}
}
Question:
It may take a while before I can switch over to an updated ActiPro, is there a way I can workaround these problems?