diff --git a/CHANGELOG.md b/CHANGELOG.md index 511b2058ad..0ee612e5be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,7 +57,7 @@ Feature #7130: Ability to set MyGUI logging verbosity Feature #7148: Optimize string literal lookup in mwscript Feature #7194: Ori to show texture paths - Feature #7214: Add search capabilities to the console window + Feature #7214: Searching in the in-game console Task #7117: Replace boost::scoped_array with std::vector Task #7151: Do not use std::strerror to get errno error message diff --git a/apps/openmw/mwgui/console.cpp b/apps/openmw/mwgui/console.cpp index 7319e87d2d..d44d517045 100644 --- a/apps/openmw/mwgui/console.cpp +++ b/apps/openmw/mwgui/console.cpp @@ -384,20 +384,20 @@ namespace MWGui { const std::string& searchTerm = mSearchTerm->getOnlyText(); - if (searchTerm.length() < minLengthOfSearchTerm) + if (searchTerm.empty()) { return; } - currentSearchTerm = Utf8Stream::lowerCaseUtf8(searchTerm); - currentOccurrence = std::string::npos; + mCurrentSearchTerm = Utf8Stream::lowerCaseUtf8(searchTerm); + mCurrentOccurrence = std::string::npos; findNextOccurrence(nullptr); } void Console::findNextOccurrence(MyGUI::Widget* _sender) { - if (currentSearchTerm.length() < minLengthOfSearchTerm) + if (mCurrentSearchTerm.empty()) { return; } @@ -408,24 +408,24 @@ namespace MWGui size_t startIndex = 0; // If this is not the first search, we start right AFTER the last occurrence. - if (currentOccurrence != std::string::npos && historyText.length() - currentOccurrence > minLengthOfSearchTerm) + if (mCurrentOccurrence != std::string::npos && historyText.length() - mCurrentOccurrence > 1) { - startIndex = currentOccurrence + minLengthOfSearchTerm; + startIndex = mCurrentOccurrence + 1; } - currentOccurrence = historyText.find(currentSearchTerm, startIndex); + mCurrentOccurrence = historyText.find(mCurrentSearchTerm, startIndex); // If the last search did not find anything AND we didn't start at // the beginning, we repeat the search one time for wrapping around the text. - if (currentOccurrence == std::string::npos && startIndex != 0) + if (mCurrentOccurrence == std::string::npos && startIndex != 0) { - currentOccurrence = historyText.find(currentSearchTerm); + mCurrentOccurrence = historyText.find(mCurrentSearchTerm); } // Only scroll & select if we actually found something - if (currentOccurrence != std::string::npos) + if (mCurrentOccurrence != std::string::npos) { - markOccurrence(currentOccurrence, currentSearchTerm.length()); + markOccurrence(mCurrentOccurrence, mCurrentSearchTerm.length()); } else { @@ -435,7 +435,7 @@ namespace MWGui void Console::findPreviousOccurence(MyGUI::Widget* _sender) { - if (currentSearchTerm.length() < minLengthOfSearchTerm) + if (mCurrentSearchTerm.empty()) { return; } @@ -446,24 +446,24 @@ namespace MWGui size_t startIndex = historyText.length(); // If this is not the first search, we start right BEFORE the last occurrence. - if (currentOccurrence != std::string::npos && currentOccurrence > minLengthOfSearchTerm) + if (mCurrentOccurrence != std::string::npos && mCurrentOccurrence > 1) { - startIndex = currentOccurrence - minLengthOfSearchTerm; + startIndex = mCurrentOccurrence - 1; } - currentOccurrence = historyText.rfind(currentSearchTerm, startIndex); + mCurrentOccurrence = historyText.rfind(mCurrentSearchTerm, startIndex); // If the last search did not find anything AND we didn't start at // the end, we repeat the search one time for wrapping around the text. - if (currentOccurrence == std::string::npos && startIndex != historyText.length()) + if (mCurrentOccurrence == std::string::npos && startIndex != historyText.length()) { - currentOccurrence = historyText.rfind(currentSearchTerm, historyText.length()); + mCurrentOccurrence = historyText.rfind(mCurrentSearchTerm, historyText.length()); } // Only scroll & select if we actually found something - if (currentOccurrence != std::string::npos) + if (mCurrentOccurrence != std::string::npos) { - markOccurrence(currentOccurrence, currentSearchTerm.length()); + markOccurrence(mCurrentOccurrence, mCurrentSearchTerm.length()); } else { diff --git a/apps/openmw/mwgui/console.hpp b/apps/openmw/mwgui/console.hpp index dd9c6b48ac..611b9577e4 100644 --- a/apps/openmw/mwgui/console.hpp +++ b/apps/openmw/mwgui/console.hpp @@ -87,9 +87,8 @@ namespace MWGui void findNextOccurrence(MyGUI::Widget* _sender); void findPreviousOccurence(MyGUI::Widget* _sender); void markOccurrence(size_t textPosition, size_t length); - size_t currentOccurrence = std::string::npos; - std::string currentSearchTerm = ""; - const size_t minLengthOfSearchTerm = 1; + size_t mCurrentOccurrence = std::string::npos; + std::string mCurrentSearchTerm; std::string complete(std::string input, std::vector& matches);