From 977d318ac8ccb756bb90a8572f01bc6825b5d0a3 Mon Sep 17 00:00:00 2001 From: Cho Date: Wed, 23 Jan 2013 20:22:28 +0000 Subject: CHUI-291 FIX New auto-replace feature does not work with chui text input boxes in conversation floater Moved autoreplace hooks from LLLineEditor to LLTextEditor, and modified LLAutoReplace accordingly --- indra/newview/llautoreplace.cpp | 50 +++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 32 deletions(-) (limited to 'indra/newview/llautoreplace.cpp') diff --git a/indra/newview/llautoreplace.cpp b/indra/newview/llautoreplace.cpp index d71cf290d6..94773e312c 100644 --- a/indra/newview/llautoreplace.cpp +++ b/indra/newview/llautoreplace.cpp @@ -30,29 +30,17 @@ #include "llviewercontrol.h" #include "llnotificationsutil.h" -LLAutoReplace* LLAutoReplace::sInstance; - const char* LLAutoReplace::SETTINGS_FILE_NAME = "autoreplace.xml"; -LLAutoReplace::LLAutoReplace() -{ -} - -LLAutoReplace::~LLAutoReplace() -{ - sInstance = NULL; -} - -void LLAutoReplace::autoreplaceCallback(LLUIString& inputText, S32& cursorPos) +void LLAutoReplace::autoreplaceCallback(LLWString& inputText, S32& cursorPos) { static LLCachedControl perform_autoreplace(gSavedSettings, "AutoReplace"); if(perform_autoreplace) { S32 wordEnd = cursorPos-1; - LLWString text = inputText.getWString(); - bool atSpace = (text[wordEnd] == ' '); - bool haveWord = (LLWStringUtil::isPartOfWord(text[wordEnd])); + bool atSpace = (inputText[wordEnd] == ' '); + bool haveWord = (LLWStringUtil::isPartOfWord(inputText[wordEnd])); if (atSpace || haveWord) { @@ -60,7 +48,7 @@ void LLAutoReplace::autoreplaceCallback(LLUIString& inputText, S32& cursorPos) { // find out if this space immediately follows a word wordEnd--; - haveWord = (LLWStringUtil::isPartOfWord(text[wordEnd])); + haveWord = (LLWStringUtil::isPartOfWord(inputText[wordEnd])); } if (haveWord) { @@ -68,14 +56,14 @@ void LLAutoReplace::autoreplaceCallback(LLUIString& inputText, S32& cursorPos) std::string word; S32 wordStart = wordEnd; for ( S32 backOne = wordStart - 1; - backOne >= 0 && LLWStringUtil::isPartOfWord(text[backOne]); + backOne >= 0 && LLWStringUtil::isPartOfWord(inputText[backOne]); backOne-- ) { wordStart--; // walk wordStart back to the beginning of the word } LL_DEBUGS("AutoReplace")<<"wordStart: "<loadFromSettings(); - } - return sInstance; -} - std::string LLAutoReplace::getUserSettingsFileName() { std::string path=gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, ""); @@ -147,6 +124,15 @@ void LLAutoReplace::setSettings(const LLAutoReplaceSettings& newSettings) saveToUserSettings(); } +LLAutoReplace::LLAutoReplace() +{ +} + +void LLAutoReplace::initSingleton() +{ + loadFromSettings(); +} + void LLAutoReplace::loadFromSettings() { std::string filename=getUserSettingsFileName(); @@ -220,7 +206,7 @@ void LLAutoReplace::saveToUserSettings() std::string filename=getUserSettingsFileName(); llofstream file; file.open(filename.c_str()); - LLSDSerialize::toPrettyXML(mSettings.getAsLLSD(), file); + LLSDSerialize::toPrettyXML(mSettings.asLLSD(), file); file.close(); LL_INFOS("AutoReplace") << "settings saved to '" << filename << "'" << LL_ENDL; } @@ -801,7 +787,7 @@ LLSD LLAutoReplaceSettings::getExampleLLSD() return example; } -const LLSD& LLAutoReplaceSettings::getAsLLSD() +const LLSD& LLAutoReplaceSettings::asLLSD() { return mLists; } -- cgit v1.2.3 From 163f3de73d93be8f5e482be03a1952244cadee68 Mon Sep 17 00:00:00 2001 From: Cho Date: Fri, 25 Jan 2013 19:53:12 +0000 Subject: CHUI-291 FIX New auto-replace feature does not work with chui text input boxes in conversation floater Modified LLAutoReplace to pass back a string for replacement instead of modifying the input string --- indra/newview/llautoreplace.cpp | 65 ++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 30 deletions(-) (limited to 'indra/newview/llautoreplace.cpp') diff --git a/indra/newview/llautoreplace.cpp b/indra/newview/llautoreplace.cpp index 94773e312c..1d72397cbc 100644 --- a/indra/newview/llautoreplace.cpp +++ b/indra/newview/llautoreplace.cpp @@ -32,53 +32,58 @@ const char* LLAutoReplace::SETTINGS_FILE_NAME = "autoreplace.xml"; -void LLAutoReplace::autoreplaceCallback(LLWString& inputText, S32& cursorPos) +void LLAutoReplace::autoreplaceCallback(S32& replacement_start, S32& replacement_length, LLWString& replacement_string, S32& cursor_pos, const LLWString& input_text) { + // make sure these returned values are cleared in case there is no replacement + replacement_start = 0; + replacement_length = 0; + replacement_string.clear(); + static LLCachedControl perform_autoreplace(gSavedSettings, "AutoReplace"); - if(perform_autoreplace) + if (perform_autoreplace) { - S32 wordEnd = cursorPos-1; + S32 word_end = cursor_pos - 1; - bool atSpace = (inputText[wordEnd] == ' '); - bool haveWord = (LLWStringUtil::isPartOfWord(inputText[wordEnd])); + bool at_space = (input_text[word_end] == ' '); + bool have_word = (LLWStringUtil::isPartOfWord(input_text[word_end])); - if (atSpace || haveWord) + if (at_space || have_word) { - if (atSpace && wordEnd > 0) + if (at_space && word_end > 0) { // find out if this space immediately follows a word - wordEnd--; - haveWord = (LLWStringUtil::isPartOfWord(inputText[wordEnd])); + word_end--; + have_word = (LLWStringUtil::isPartOfWord(input_text[word_end])); } - if (haveWord) + if (have_word) { - // wordEnd points to the end of a word, now find the start of the word + // word_end points to the end of a word, now find the start of the word std::string word; - S32 wordStart = wordEnd; - for ( S32 backOne = wordStart - 1; - backOne >= 0 && LLWStringUtil::isPartOfWord(inputText[backOne]); - backOne-- - ) + S32 word_start = word_end; + for (S32 back_one = word_start - 1; + back_one >= 0 && LLWStringUtil::isPartOfWord(input_text[back_one]); + back_one-- + ) { - wordStart--; // walk wordStart back to the beginning of the word + word_start--; // walk word_start back to the beginning of the word } - LL_DEBUGS("AutoReplace")<<"wordStart: "<