diff --git a/src/calibre/spell/dictionary.py b/src/calibre/spell/dictionary.py index af61800ef7..05ffdb7d92 100644 --- a/src/calibre/spell/dictionary.py +++ b/src/calibre/spell/dictionary.py @@ -339,6 +339,10 @@ class Dictionaries(object): locale = locale or self.default_locale d = self.dictionary_for_locale(locale) ans = () + + def add_suggestion(w, ans): + return (w,) + tuple(x for x in ans if x != w) + if d is not None: try: ans = d.obj.suggest(unicode(word)) @@ -348,17 +352,17 @@ class Dictionaries(object): dehyphenated_word = self.remove_hyphenation.sub('', word) if len(dehyphenated_word) != len(word) and self.recognized(dehyphenated_word, locale): # Ensure the de-hyphenated word is present and is the first suggestion - ans = (dehyphenated_word,) + tuple(x for x in ans if x != dehyphenated_word) + ans = add_suggestion(dehyphenated_word, ans) else: m = self.fix_punctuation_pat.search(word) if m is not None: w1, w2 = word[:m.start()], word[m.end():] if self.recognized(w1) and self.recognized(w2): fw = w1 + m.group() + ' ' + w2 - ans = (fw,) + ans + ans = add_suggestion(fw, ans) if capitalize(w2) != w2: fw = w1 + m.group() + ' ' + capitalize(w2) - ans = (fw,) + ans + ans = add_suggestion(fw, ans) return ans