Browse Source

Incremental search allows case sensitive searches. If all the characters of the search text are lower case the search is case insensitive. If any character is upper case the search is case sensitive.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1781 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 20 years ago
parent
commit
761b8bf89a
  1. 32
      src/Main/Base/Project/Src/TextEditor/Gui/Editor/IncrementalSearch.cs

32
src/Main/Base/Project/Src/TextEditor/Gui/Editor/IncrementalSearch.cs

@ -81,7 +81,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
EnableIncrementalSearchCursor(); EnableIncrementalSearchCursor();
// Get text to search and initial search position. // Get text to search and initial search position.
text = textEditor.Document.TextContent.ToLowerInvariant(); text = textEditor.Document.TextContent;
startIndex = TextArea.Caret.Offset; startIndex = TextArea.Caret.Offset;
originalStartIndex = startIndex; originalStartIndex = startIndex;
@ -191,18 +191,36 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
/// <summary> /// <summary>
/// Looks for the string from the last position we searched from. The /// Looks for the string from the last position we searched from. The
/// search is case insensitive. The search can be either forwards /// search is case insensitive if all the characters of the search
/// string are lower case. If one of the search characters is upper case
/// then the search is case sensitive. The search can be either forwards
/// or backwards. /// or backwards.
/// </summary> /// </summary>
int FindText(string s, int startIndex, bool forwards) int FindText(string find, int startIndex, bool forwards)
{ {
string find = s.ToLowerInvariant(); StringComparison stringComparison = GetStringComparisonType(find);
if (forwards) { if (forwards) {
return text.IndexOf(find, startIndex); return text.IndexOf(find, startIndex, stringComparison);
} }
// Reverse search. // Reverse search.
string searchText = GetReverseSearchText(startIndex + find.Length); string searchText = GetReverseSearchText(startIndex + find.Length);
return searchText.LastIndexOf(find); return searchText.LastIndexOf(find, stringComparison);
}
/// <summary>
/// Gets whether the search string comparision should be case
/// sensitive. If all the characters of the find string are lower case
/// then the search is case insensitive. If any character is upper case
/// then the search is case sensitive.
/// </summary>
StringComparison GetStringComparisonType(string find)
{
foreach (char c in find) {
if (Char.IsUpper(c)) {
return StringComparison.InvariantCulture;
}
}
return StringComparison.InvariantCultureIgnoreCase;
} }
/// <summary> /// <summary>
@ -211,7 +229,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
string GetReverseSearchText(int endIndex) string GetReverseSearchText(int endIndex)
{ {
if (endIndex < text.Length) { if (endIndex < text.Length) {
return text.Substring(0, endIndex + 1); return text.Substring(0, endIndex);
} }
endIndex = text.Length - 1; endIndex = text.Length - 1;
if (endIndex >= 0) { if (endIndex >= 0) {

Loading…
Cancel
Save