Fix handling of thesaurus words with only a single suggestion

When there's only one suggestion for a given word the part of speech
appears in the suggested replacement, which needs to be stripped.

Closes #1776.
This commit is contained in:
Thomas Goyne 2014-06-23 15:49:30 -07:00
parent 5ece2e534c
commit 4ce1283bbb
1 changed files with 16 additions and 3 deletions

View File

@ -479,10 +479,23 @@ void SubsTextEditCtrl::OnUseSuggestion(wxCommandEvent &event) {
else
suggestion = sugs[event.GetId() - EDIT_MENU_SUGGESTIONS];
// Strip suggestion of parenthesis
size_t pos = suggestion.find("(");
if (pos != suggestion.npos)
size_t pos;
while ((pos = suggestion.rfind('(')) != std::string::npos) {
// If there's only one suggestion for a word it'll be in the form "(noun) word",
// so we need to trim the "(noun) " part
if (pos == 0) {
pos = suggestion.find(')');
if (pos != std::string::npos) {
if (pos + 1< suggestion.size() && suggestion[pos + 1] == ' ') ++pos;
suggestion.erase(0, pos + 1);
}
break;
}
// Some replacements have notes about their usage after the word in the
// form "word (generic term)" that we need to remove (plus the leading space)
suggestion.resize(pos - 1);
}
// line_text needs to get cleared before SetTextRaw to ensure it gets reparsed
std::string new_text;