diff --git a/indra/llui/lllineeditor.cpp b/indra/llui/lllineeditor.cpp index 779c5a5523..4e0c5ddfdc 100644 --- a/indra/llui/lllineeditor.cpp +++ b/indra/llui/lllineeditor.cpp @@ -536,6 +536,31 @@ U32 LLLineEditor::getSuggestionCount() const return mSuggestionList.size(); } +void LLLineEditor::replaceWithSuggestion(U32 idxSuggestion) +{ + for (std::list >::const_iterator itMisspell = mMisspellRanges.begin(); + itMisspell != mMisspellRanges.end(); ++itMisspell) + { + if ( (itMisspell->first <= (U32)mCursorPos) && (itMisspell->second >= (U32)mCursorPos) ) + { + deselect(); + + // Delete the misspelled word + mText.erase(itMisspell->first, itMisspell->second - itMisspell->first); + setCursor(itMisspell->first); + + // Insert the suggestion in its place + LLWString wstrSuggestion = utf8str_to_wstring(mSuggestionList[idxSuggestion]); + mText.insert(getCursor(), wstrSuggestion); + + setCursor(mCursorPos + (S32)wstrSuggestion.length()); + + break; + } + } + mNeedsSpellCheck = TRUE; +} + void LLLineEditor::addToDictionary() { // TODO: implement this diff --git a/indra/llui/lllineeditor.h b/indra/llui/lllineeditor.h index 8582b967f1..634379455c 100644 --- a/indra/llui/lllineeditor.h +++ b/indra/llui/lllineeditor.h @@ -158,6 +158,7 @@ public: /*virtual*/ std::string getSuggestion(U32 idxSuggestion) const; /*virtual*/ U32 getSuggestionCount() const; + /*virtual*/ void replaceWithSuggestion(U32 idxSuggestion); /*virtual*/ void addToDictionary(); /*virtual*/ bool canAddToDictionary() const; diff --git a/indra/llui/llmenugl.cpp b/indra/llui/llmenugl.cpp index 929eab8e16..a79415f2c1 100644 --- a/indra/llui/llmenugl.cpp +++ b/indra/llui/llmenugl.cpp @@ -3937,7 +3937,8 @@ void LLContextMenu::hide() } mHoverItem = NULL; // [SL:KB] - Patch: Misc-Spellcheck | Checked: 2010-12-19 (Catznip-2.5.0a) | Added: Catznip-2.5.0a - mSpawningViewHandle.markDead(); + // NOTE: this should be done *somewhere* but a menu item's onCommit() calls "hideMenus" before it fires the "onCommit" signal +// mSpawningViewHandle.markDead(); // [/SL:KB] } diff --git a/indra/llui/llspellcheckmenuhandler.h b/indra/llui/llspellcheckmenuhandler.h index cd84e2d064..5465a478d5 100644 --- a/indra/llui/llspellcheckmenuhandler.h +++ b/indra/llui/llspellcheckmenuhandler.h @@ -26,6 +26,7 @@ public: virtual std::string getSuggestion(U32 idxSuggestion) const { return ""; } virtual U32 getSuggestionCount() const { return 0; } + virtual void replaceWithSuggestion(U32 idxSuggestion) {} virtual void addToDictionary() {} virtual bool canAddToDictionary() const { return false; } diff --git a/indra/newview/llviewermenu.cpp b/indra/newview/llviewermenu.cpp index 1ff195855c..c06662e029 100644 --- a/indra/newview/llviewermenu.cpp +++ b/indra/newview/llviewermenu.cpp @@ -5064,6 +5064,16 @@ class LLViewEnableLastChatter : public view_listener_t // [SL:KB] - Patch: Misc-Spellcheck | Checked: 2010-12-19 (Catznip-2.5.0a) | Added: Catznip-2.5.0a void spellCheck_ReplaceWithSuggestion(LLUICtrl* pMenuItemCtrl, const LLSD& sdParam) { + LLContextMenu* pMenu = dynamic_cast(pMenuItemCtrl->getParent()); + LLSpellCheckMenuHandler* pSpellCheckHandler = (pMenu) ? dynamic_cast(pMenu->getSpawningView()) : NULL; + if ( (!pSpellCheckHandler) || (!pSpellCheckHandler->useSpellCheck()) ) + return; + + U32 idxSuggestion = 0; + if ( (!LLStringUtil::convertToU32(sdParam.asString(), idxSuggestion)) || (idxSuggestion >= pSpellCheckHandler->getSuggestionCount()) ) + return; + + pSpellCheckHandler->replaceWithSuggestion(idxSuggestion); } bool spellCheck_VisibleSuggestion(LLUICtrl* pMenuItemCtrl, const LLSD& sdParam)