From 761b8bf89a5538e250fc07b477bd129276991568 Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Sun, 10 Sep 2006 11:27:14 +0000 Subject: [PATCH] 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 --- .../Gui/Editor/IncrementalSearch.cs | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/Main/Base/Project/Src/TextEditor/Gui/Editor/IncrementalSearch.cs b/src/Main/Base/Project/Src/TextEditor/Gui/Editor/IncrementalSearch.cs index b90d9de504..1c41394082 100644 --- a/src/Main/Base/Project/Src/TextEditor/Gui/Editor/IncrementalSearch.cs +++ b/src/Main/Base/Project/Src/TextEditor/Gui/Editor/IncrementalSearch.cs @@ -81,7 +81,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor EnableIncrementalSearchCursor(); // Get text to search and initial search position. - text = textEditor.Document.TextContent.ToLowerInvariant(); + text = textEditor.Document.TextContent; startIndex = TextArea.Caret.Offset; originalStartIndex = startIndex; @@ -191,18 +191,36 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor /// /// 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. /// - 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) { - return text.IndexOf(find, startIndex); + return text.IndexOf(find, startIndex, stringComparison); } // Reverse search. string searchText = GetReverseSearchText(startIndex + find.Length); - return searchText.LastIndexOf(find); + return searchText.LastIndexOf(find, stringComparison); + } + + /// + /// 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. + /// + StringComparison GetStringComparisonType(string find) + { + foreach (char c in find) { + if (Char.IsUpper(c)) { + return StringComparison.InvariantCulture; + } + } + return StringComparison.InvariantCultureIgnoreCase; } /// @@ -211,7 +229,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor string GetReverseSearchText(int endIndex) { if (endIndex < text.Length) { - return text.Substring(0, endIndex + 1); + return text.Substring(0, endIndex); } endIndex = text.Length - 1; if (endIndex >= 0) {