From 4ce1283bbbf2e65be40b833ad0c9e646382ae978 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Mon, 23 Jun 2014 15:49:30 -0700 Subject: [PATCH] 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. --- src/subs_edit_ctrl.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/subs_edit_ctrl.cpp b/src/subs_edit_ctrl.cpp index 4934afbc7..d5e5bacd7 100644 --- a/src/subs_edit_ctrl.cpp +++ b/src/subs_edit_ctrl.cpp @@ -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;