diff options
-rw-r--r-- | indra/llui/lltexteditor.cpp | 25 | ||||
-rw-r--r-- | indra/llui/lltexteditor.h | 8 | ||||
-rw-r--r-- | indra/newview/llautoreplace.cpp | 65 | ||||
-rw-r--r-- | indra/newview/llautoreplace.h | 5 | ||||
-rw-r--r-- | indra/newview/llfloaterimnearbychat.cpp | 4 | ||||
-rw-r--r-- | indra/newview/llfloaterimsession.cpp | 4 | ||||
-rw-r--r-- | indra/newview/llimview.cpp | 12 |
7 files changed, 70 insertions, 53 deletions
diff --git a/indra/llui/lltexteditor.cpp b/indra/llui/lltexteditor.cpp index d297e54f2f..562bbc7100 100644 --- a/indra/llui/lltexteditor.cpp +++ b/indra/llui/lltexteditor.cpp @@ -246,8 +246,8 @@ LLTextEditor::Params::Params() } LLTextEditor::LLTextEditor(const LLTextEditor::Params& p) : - LLTextBase(p), - mAutoreplaceCallback(), + LLTextBase(p), + mAutoreplaceCallback(), mBaseDocIsPristine(TRUE), mPristineCmd( NULL ), mLastCmd( NULL ), @@ -1099,11 +1099,22 @@ void LLTextEditor::addChar(llwchar wc) setCursorPos(mCursorPos + addChar( mCursorPos, wc )); - if (!mReadOnly && mAutoreplaceCallback != NULL) - { - // call callback - mAutoreplaceCallback(getViewModel()->getEditableDisplay(), mCursorPos); - } + if (!mReadOnly && mAutoreplaceCallback != NULL) + { + // autoreplace the text, if necessary + S32 replacement_start; + S32 replacement_length; + LLWString replacement_string; + S32 new_cursor_pos = mCursorPos; + mAutoreplaceCallback(replacement_start, replacement_length, replacement_string, new_cursor_pos, getWText()); + + if (replacement_length > 0 || !replacement_string.empty()) + { + remove(replacement_start, replacement_length, true); + insert(replacement_start, replacement_string, false, LLTextSegmentPtr()); + setCursorPos(new_cursor_pos); + } + } } void LLTextEditor::addLineBreakChar() diff --git a/indra/llui/lltexteditor.h b/indra/llui/lltexteditor.h index ae5a983b60..5e189070fa 100644 --- a/indra/llui/lltexteditor.h +++ b/indra/llui/lltexteditor.h @@ -157,10 +157,10 @@ public: BOOL isPristine() const; BOOL allowsEmbeddedItems() const { return mAllowEmbeddedItems; } - // Autoreplace (formerly part of LLLineEditor) - typedef boost::function<void(LLWString&, S32&)> autoreplace_callback_t; - autoreplace_callback_t mAutoreplaceCallback; - void setAutoreplaceCallback(autoreplace_callback_t cb) { mAutoreplaceCallback = cb; } + // Autoreplace (formerly part of LLLineEditor) + typedef boost::function<void(S32&, S32&, LLWString&, S32&, const LLWString&)> autoreplace_callback_t; + autoreplace_callback_t mAutoreplaceCallback; + void setAutoreplaceCallback(autoreplace_callback_t cb) { mAutoreplaceCallback = cb; } // // Text manipulation 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<bool> 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: "<<wordStart<<" wordEnd: "<<wordEnd<<LL_ENDL; - std::string strText = std::string(inputText.begin(), inputText.end()); - std::string lastWord = strText.substr(wordStart, wordEnd-wordStart+1); - std::string replacementWord( mSettings.replaceWord( lastWord ) ); + LL_DEBUGS("AutoReplace") << "word_start: " << word_start << " word_end: " << word_end << LL_ENDL; + std::string str_text = std::string(input_text.begin(), input_text.end()); + std::string last_word = str_text.substr(word_start, word_end - word_start + 1); + std::string replacement_word(mSettings.replaceWord(last_word)); - if ( replacementWord != lastWord ) + if (replacement_word != last_word) { // The last word is one for which we have a replacement - if (atSpace) + if (at_space) { - // replace the last word in the input - LLWString strNew = utf8str_to_wstring(replacementWord); - LLWString strOld = utf8str_to_wstring(lastWord); - int size_change = strNew.size() - strOld.size(); - - inputText.replace(wordStart,lastWord.length(),strNew); - cursorPos+=size_change; + // return the replacement string + replacement_start = word_start; + replacement_length = last_word.length(); + replacement_string = utf8str_to_wstring(replacement_word); + LLWString old_string = utf8str_to_wstring(last_word); + S32 size_change = replacement_string.size() - old_string.size(); + cursor_pos += size_change; } } } diff --git a/indra/newview/llautoreplace.h b/indra/newview/llautoreplace.h index bbb86294bc..9eecc2d981 100644 --- a/indra/newview/llautoreplace.h +++ b/indra/newview/llautoreplace.h @@ -183,7 +183,8 @@ class LLAutoReplaceSettings * When the end of a word is detected (defined as any punctuation character, * or any whitespace except newline or return), the preceding word is used * as a lookup key in an ordered list of maps. If a match is found in any - * map, the keyword is replaced by the associated value from the map. + * map, the replacement start index and length are returned along with the + * new replacement string. * * See the autoreplaceCallback method for how to add autoreplace functionality * to a text entry tool. @@ -192,7 +193,7 @@ class LLAutoReplace : public LLSingleton<LLAutoReplace> { public: /// Callback that provides the hook for use in text entry methods - void autoreplaceCallback(LLWString& inputText, S32& cursorPos); + void autoreplaceCallback(S32& replacement_start, S32& replacement_length, LLWString& replacement_string, S32& cursor_pos, const LLWString& input_text); /// Get a copy of the current settings LLAutoReplaceSettings getSettings(); diff --git a/indra/newview/llfloaterimnearbychat.cpp b/indra/newview/llfloaterimnearbychat.cpp index a01578fa22..a2dd93e10d 100644 --- a/indra/newview/llfloaterimnearbychat.cpp +++ b/indra/newview/llfloaterimnearbychat.cpp @@ -112,8 +112,8 @@ BOOL LLFloaterIMNearbyChat::postBuild() { setIsSingleInstance(TRUE); BOOL result = LLFloaterIMSessionTab::postBuild(); - - mInputEditor->setAutoreplaceCallback(boost::bind(&LLAutoReplace::autoreplaceCallback, LLAutoReplace::getInstance(), _1, _2)); + + mInputEditor->setAutoreplaceCallback(boost::bind(&LLAutoReplace::autoreplaceCallback, LLAutoReplace::getInstance(), _1, _2, _3, _4, _5)); mInputEditor->setCommitCallback(boost::bind(&LLFloaterIMNearbyChat::onChatBoxCommit, this)); mInputEditor->setKeystrokeCallback(boost::bind(&LLFloaterIMNearbyChat::onChatBoxKeystroke, this)); mInputEditor->setFocusLostCallback(boost::bind(&LLFloaterIMNearbyChat::onChatBoxFocusLost, this)); diff --git a/indra/newview/llfloaterimsession.cpp b/indra/newview/llfloaterimsession.cpp index 7ed683d701..f754853b82 100644 --- a/indra/newview/llfloaterimsession.cpp +++ b/indra/newview/llfloaterimsession.cpp @@ -162,7 +162,7 @@ void LLFloaterIMSession::newIMCallback(const LLSD& data) LLFloaterIMSession* floater = LLFloaterReg::findTypedInstance<LLFloaterIMSession>("impanel", session_id); // update if visible, otherwise will be updated when opened - if (floater && (floater->getHost()? floater->hasFocus() : floater->getVisible())) + if (floater && floater->isInVisibleChain()) { floater->updateMessages(); } @@ -332,7 +332,7 @@ BOOL LLFloaterIMSession::postBuild() BOOL result = LLFloaterIMSessionTab::postBuild(); mInputEditor->setMaxTextLength(1023); - mInputEditor->setAutoreplaceCallback(boost::bind(&LLAutoReplace::autoreplaceCallback, LLAutoReplace::getInstance(), _1, _2)); + mInputEditor->setAutoreplaceCallback(boost::bind(&LLAutoReplace::autoreplaceCallback, LLAutoReplace::getInstance(), _1, _2, _3, _4, _5)); mInputEditor->setFocusReceivedCallback( boost::bind(onInputEditorFocusReceived, _1, this) ); mInputEditor->setFocusLostCallback( boost::bind(onInputEditorFocusLost, _1, this) ); mInputEditor->setKeystrokeCallback( boost::bind(onInputEditorKeystroke, _1, this) ); diff --git a/indra/newview/llimview.cpp b/indra/newview/llimview.cpp index 37c9ee8c99..8f010850f7 100644 --- a/indra/newview/llimview.cpp +++ b/indra/newview/llimview.cpp @@ -237,7 +237,7 @@ void on_new_message(const LLSD& msg) LLAvatarNameCache::get(participant_id, boost::bind(&on_avatar_name_cache_toast, _1, _2, msg)); } } - } + } } else if ("flash" == action) @@ -273,9 +273,9 @@ void on_new_message(const LLSD& msg) if(!gAgent.isDoNotDisturb()) { - //Surface conversations floater - LLFloaterReg::showInstance("im_container"); - } + //Surface conversations floater + LLFloaterReg::showInstance("im_container"); + } //If in DND mode, allow notification to be stored so upon DND exit //useMostItrusiveIMNotification will be called to notify user a message exists @@ -284,8 +284,8 @@ void on_new_message(const LLSD& msg) && gAgent.isDoNotDisturb()) { LLAvatarNameCache::get(participant_id, boost::bind(&on_avatar_name_cache_toast, _1, _2, msg)); - } -} + } + } } } |