Clean up a bunch of spelling suggestion code that's annoyed me forever
This commit is contained in:
@@ -443,28 +443,9 @@ void LLLineEditor::deselect()
|
||||
}
|
||||
|
||||
|
||||
void LLLineEditor::spell_correct(void* data)
|
||||
void LLLineEditor::spell_show(void* show)
|
||||
{
|
||||
SpellMenuBind* tempBind = (SpellMenuBind*)data;
|
||||
LLLineEditor* line = tempBind->origin;
|
||||
if(tempBind && line)
|
||||
{
|
||||
LL_INFOS() << ((LLMenuItemCallGL *)(tempBind->menuItem))->getName() << " : " << tempBind->origin->getName() << " : " << tempBind->word << LL_ENDL;
|
||||
if(line)line->spellReplace(tempBind);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void LLLineEditor::spell_show(void * data)
|
||||
{
|
||||
SpellMenuBind* tempBind = (SpellMenuBind*)data;
|
||||
LLLineEditor* line = tempBind->origin;
|
||||
|
||||
if (tempBind && line)
|
||||
{
|
||||
BOOL show = (tempBind->word == "Show Misspellings");
|
||||
glggHunSpell->setSpellCheckHighlight(show);
|
||||
}
|
||||
glggHunSpell->setSpellCheckHighlight(!!show);
|
||||
}
|
||||
|
||||
std::vector<S32> LLLineEditor::getMisspelledWordsPositions()
|
||||
@@ -516,11 +497,12 @@ std::vector<S32> LLLineEditor::getMisspelledWordsPositions()
|
||||
|
||||
void LLLineEditor::spell_add(void* data)
|
||||
{
|
||||
SpellMenuBind* tempBind = (SpellMenuBind*)data;
|
||||
if(tempBind)
|
||||
auto self = static_cast<LLLineEditor*>(data);
|
||||
S32 wordStart = 0, wordLen = 0;
|
||||
if (self->getWordBoundriesAt(self->calculateCursorFromMouse(self->mLastContextMenuX), &wordStart, &wordLen))
|
||||
{
|
||||
glggHunSpell->addWordToCustomDictionary(tempBind->word);
|
||||
tempBind->origin->mPrevSpelledText="";//make it update
|
||||
glggHunSpell->addWordToCustomDictionary(wstring_to_utf8str(self->getWText().substr(wordStart, wordLen)));
|
||||
self->mPrevSpelledText.clear(); //make it update
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1149,12 +1131,19 @@ void LLLineEditor::copy()
|
||||
}
|
||||
|
||||
|
||||
void LLLineEditor::spellReplace(SpellMenuBind* spellData)
|
||||
void LLLineEditor::spell_correct(void* data)
|
||||
{
|
||||
mText.erase(spellData->wordPositionStart,
|
||||
spellData->wordPositionEnd - spellData->wordPositionStart);
|
||||
insert(spellData->word,spellData->wordPositionStart);
|
||||
mCursorPos+=spellData->word.length() - (spellData->wordPositionEnd-spellData->wordPositionStart);
|
||||
auto self = static_cast<LLLineEditor*>(data);
|
||||
S32 wordStart = 0, wordLen = 0;
|
||||
if (self->getWordBoundriesAt(self->calculateCursorFromMouse(self->mLastContextMenuX), &wordStart, &wordLen))
|
||||
{
|
||||
auto word = utf8str_to_wstring(LLMenuGL::sMenuContainer->getActivatedItem()->getLabel());
|
||||
LLWStringUtil::replaceTabsWithSpaces(word, 4);
|
||||
|
||||
self->mText.erase(wordStart, wordLen);
|
||||
self->mText.insert(wordStart, word);
|
||||
self->mCursorPos += word.length() - wordLen;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3017,15 +3006,6 @@ void LLLineEditor::showContextMenu(S32 x, S32 y)
|
||||
{
|
||||
gEditMenuHandler = this;
|
||||
|
||||
/*S32 screen_x, screen_y;
|
||||
localPointToScreen(x, y, &screen_x, &screen_y);
|
||||
menu->show(screen_x, screen_y);*/
|
||||
|
||||
|
||||
//setCursorAtLocalPos( x);
|
||||
S32 wordStart = 0;
|
||||
S32 wordLen = 0;
|
||||
S32 pos = calculateCursorFromMouse(x);
|
||||
|
||||
LLMenuGL* menu = (LLMenuGL*)mContextMenuHandle.get();
|
||||
if (menu)
|
||||
@@ -3034,77 +3014,33 @@ void LLLineEditor::showContextMenu(S32 x, S32 y)
|
||||
{
|
||||
menu->setVisible(FALSE);
|
||||
}
|
||||
for (int i = 0;i<(int)suggestionMenuItems.size();i++)
|
||||
{
|
||||
SpellMenuBind * tempBind = suggestionMenuItems[i];
|
||||
if(tempBind)
|
||||
{
|
||||
menu->removeChild((LLMenuItemCallGL *)tempBind->menuItem);
|
||||
((LLMenuItemCallGL *)tempBind->menuItem)->die();
|
||||
//delete tempBind->menuItem;
|
||||
//tempBind->menuItem = NULL;
|
||||
delete tempBind;
|
||||
}
|
||||
}
|
||||
suggestionMenuItems.clear();
|
||||
|
||||
// spell_check="true" in xui
|
||||
menu->setItemVisible("Spelsep", !mReadOnly && mSpellCheckable);
|
||||
if (!mReadOnly && mSpellCheckable)
|
||||
{
|
||||
// search for word matches
|
||||
bool is_word_part = getWordBoundriesAt(pos, &wordStart, &wordLen);
|
||||
if (is_word_part)
|
||||
S32 wordStart = 0;
|
||||
S32 wordLen = 0;
|
||||
S32 pos = calculateCursorFromMouse(x);
|
||||
if (getWordBoundriesAt(pos, &wordStart, &wordLen))
|
||||
{
|
||||
const LLWString& text = mText.getWString();
|
||||
std::string selectedWord(std::string(text.begin(), text.end()).substr(wordStart,wordLen));
|
||||
|
||||
if (!glggHunSpell->isSpelledRight(selectedWord))
|
||||
{
|
||||
//misspelled word here, and you have just right clicked on it!
|
||||
std::vector<std::string> suggs = glggHunSpell->getSuggestionList(selectedWord);
|
||||
const auto selectedWord = wstring_to_utf8str(getWText().substr(wordStart, wordLen));
|
||||
|
||||
for (int i = 0; i<(int)suggs.size() ;i++)
|
||||
if (!glggHunSpell->isSpelledRight(selectedWord))
|
||||
{
|
||||
//misspelled word here, and you have just right clicked on it!
|
||||
|
||||
for (const auto& word : glggHunSpell->getSuggestionList(selectedWord))
|
||||
{
|
||||
SpellMenuBind * tempStruct = new SpellMenuBind;
|
||||
tempStruct->origin = this;
|
||||
tempStruct->word = suggs[i];
|
||||
tempStruct->wordPositionEnd = wordStart + wordLen;
|
||||
tempStruct->wordPositionStart=wordStart;
|
||||
LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL(
|
||||
tempStruct->word, spell_correct, NULL, tempStruct);
|
||||
tempStruct->menuItem = suggMenuItem;
|
||||
suggestionMenuItems.push_back(tempStruct);
|
||||
menu->addChild(suggMenuItem);
|
||||
menu->addChild(new LLMenuItemCallGL(word, spell_correct, nullptr, this));
|
||||
}
|
||||
SpellMenuBind * tempStruct = new SpellMenuBind;
|
||||
tempStruct->origin = this;
|
||||
tempStruct->word = selectedWord;
|
||||
tempStruct->wordPositionEnd = wordStart + wordLen;
|
||||
tempStruct->wordPositionStart=wordStart;
|
||||
LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL(
|
||||
"Add Word", spell_add, NULL, tempStruct);
|
||||
tempStruct->menuItem = suggMenuItem;
|
||||
suggestionMenuItems.push_back(tempStruct);
|
||||
menu->addChild(suggMenuItem);
|
||||
menu->addChild(new LLMenuItemCallGL("Add Word", spell_add, nullptr, this));
|
||||
}
|
||||
}
|
||||
|
||||
SpellMenuBind * tempStruct = new SpellMenuBind;
|
||||
tempStruct->origin = this;
|
||||
if (glggHunSpell->getSpellCheckHighlight())
|
||||
{
|
||||
tempStruct->word = "Hide Misspellings";
|
||||
}
|
||||
else
|
||||
{
|
||||
tempStruct->word = "Show Misspellings";
|
||||
}
|
||||
LLMenuItemCallGL * suggMenuItem = new LLMenuItemCallGL(
|
||||
tempStruct->word, spell_show, NULL, tempStruct);
|
||||
tempStruct->menuItem = suggMenuItem;
|
||||
suggestionMenuItems.push_back(tempStruct);
|
||||
menu->addChild(suggMenuItem);
|
||||
bool show = !glggHunSpell->getSpellCheckHighlight();
|
||||
auto word = show ? "Show Misspellings" : "Hide Misspellings";
|
||||
menu->addChild(new LLMenuItemCallGL(word, spell_show, nullptr, show ? &show : nullptr));
|
||||
}
|
||||
|
||||
mLastContextMenuX = x;
|
||||
|
||||
Reference in New Issue
Block a user