1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-06-19 18:11:35 +00:00

Resolve minor errors

This commit is contained in:
Shihan42 2023-02-22 20:15:45 +01:00
parent d76ae478aa
commit 902cad77c8
3 changed files with 22 additions and 23 deletions

View file

@ -57,7 +57,7 @@
Feature #7130: Ability to set MyGUI logging verbosity Feature #7130: Ability to set MyGUI logging verbosity
Feature #7148: Optimize string literal lookup in mwscript Feature #7148: Optimize string literal lookup in mwscript
Feature #7194: Ori to show texture paths 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 #7117: Replace boost::scoped_array with std::vector
Task #7151: Do not use std::strerror to get errno error message Task #7151: Do not use std::strerror to get errno error message

View file

@ -384,20 +384,20 @@ namespace MWGui
{ {
const std::string& searchTerm = mSearchTerm->getOnlyText(); const std::string& searchTerm = mSearchTerm->getOnlyText();
if (searchTerm.length() < minLengthOfSearchTerm) if (searchTerm.empty())
{ {
return; return;
} }
currentSearchTerm = Utf8Stream::lowerCaseUtf8(searchTerm); mCurrentSearchTerm = Utf8Stream::lowerCaseUtf8(searchTerm);
currentOccurrence = std::string::npos; mCurrentOccurrence = std::string::npos;
findNextOccurrence(nullptr); findNextOccurrence(nullptr);
} }
void Console::findNextOccurrence(MyGUI::Widget* _sender) void Console::findNextOccurrence(MyGUI::Widget* _sender)
{ {
if (currentSearchTerm.length() < minLengthOfSearchTerm) if (mCurrentSearchTerm.empty())
{ {
return; return;
} }
@ -408,24 +408,24 @@ namespace MWGui
size_t startIndex = 0; size_t startIndex = 0;
// If this is not the first search, we start right AFTER the last occurrence. // 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 // 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. // 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 // 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 else
{ {
@ -435,7 +435,7 @@ namespace MWGui
void Console::findPreviousOccurence(MyGUI::Widget* _sender) void Console::findPreviousOccurence(MyGUI::Widget* _sender)
{ {
if (currentSearchTerm.length() < minLengthOfSearchTerm) if (mCurrentSearchTerm.empty())
{ {
return; return;
} }
@ -446,24 +446,24 @@ namespace MWGui
size_t startIndex = historyText.length(); size_t startIndex = historyText.length();
// If this is not the first search, we start right BEFORE the last occurrence. // 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 // 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. // 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 // 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 else
{ {

View file

@ -87,9 +87,8 @@ namespace MWGui
void findNextOccurrence(MyGUI::Widget* _sender); void findNextOccurrence(MyGUI::Widget* _sender);
void findPreviousOccurence(MyGUI::Widget* _sender); void findPreviousOccurence(MyGUI::Widget* _sender);
void markOccurrence(size_t textPosition, size_t length); void markOccurrence(size_t textPosition, size_t length);
size_t currentOccurrence = std::string::npos; size_t mCurrentOccurrence = std::string::npos;
std::string currentSearchTerm = ""; std::string mCurrentSearchTerm;
const size_t minLengthOfSearchTerm = 1;
std::string complete(std::string input, std::vector<std::string>& matches); std::string complete(std::string input, std::vector<std::string>& matches);