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/llui/lltexteditor.cpp | 19 +++++----- indra/llui/lltexteditor.h | 2 +- indra/newview/llautoreplace.cpp | 65 ++++++++++++++++++--------------- indra/newview/llautoreplace.h | 5 ++- indra/newview/llfloaterimnearbychat.cpp | 2 +- indra/newview/llfloaterimsession.cpp | 2 +- 6 files changed, 51 insertions(+), 44 deletions(-) diff --git a/indra/llui/lltexteditor.cpp b/indra/llui/lltexteditor.cpp index 42c5f150dc..562bbc7100 100644 --- a/indra/llui/lltexteditor.cpp +++ b/indra/llui/lltexteditor.cpp @@ -1101,16 +1101,17 @@ void LLTextEditor::addChar(llwchar wc) if (!mReadOnly && mAutoreplaceCallback != NULL) { - // autoreplace on a copy of the text (so we can go through proper channels to set it later) - LLWString new_text(getWText()); - S32 new_cursor_pos(mCursorPos); - mAutoreplaceCallback(new_text, new_cursor_pos); - - if (new_text != getWText()) + // 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()) { - // setText() might be simpler here but it wipes the undo stack (bad) - remove(0, getWText().length(), true); - insert(0, new_text, false, LLTextSegmentPtr()); + remove(replacement_start, replacement_length, true); + insert(replacement_start, replacement_string, false, LLTextSegmentPtr()); setCursorPos(new_cursor_pos); } } diff --git a/indra/llui/lltexteditor.h b/indra/llui/lltexteditor.h index 7f0dbc9865..5e189070fa 100644 --- a/indra/llui/lltexteditor.h +++ b/indra/llui/lltexteditor.h @@ -158,7 +158,7 @@ public: BOOL allowsEmbeddedItems() const { return mAllowEmbeddedItems; } // Autoreplace (formerly part of LLLineEditor) - typedef boost::function autoreplace_callback_t; + typedef boost::function autoreplace_callback_t; autoreplace_callback_t mAutoreplaceCallback; void setAutoreplaceCallback(autoreplace_callback_t cb) { mAutoreplaceCallback = cb; } 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: "< { 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 38f49e76d4..a2dfd4b53e 100644 --- a/indra/newview/llfloaterimnearbychat.cpp +++ b/indra/newview/llfloaterimnearbychat.cpp @@ -113,7 +113,7 @@ 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 a2c7bacb5d..a08479c7be 100644 --- a/indra/newview/llfloaterimsession.cpp +++ b/indra/newview/llfloaterimsession.cpp @@ -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) ); -- cgit v1.2.3