From 643d305548c32c0c5f6a989320a8f147a8d1c0be Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 21 Apr 2014 12:09:07 +0530 Subject: [PATCH] Fix find next occurrence skipping some matches if a stem word maps to more than a single original word --- src/calibre/gui2/tweak_book/editor/text.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/calibre/gui2/tweak_book/editor/text.py b/src/calibre/gui2/tweak_book/editor/text.py index 745a726536..fda4d47176 100644 --- a/src/calibre/gui2/tweak_book/editor/text.py +++ b/src/calibre/gui2/tweak_book/editor/text.py @@ -385,16 +385,17 @@ class TextEdit(PlainTextEdit): c.movePosition(c.Start) c.movePosition(c.End, c.KeepAnchor) - def find_word(haystack): + def find_first_word(haystack): + match_pos, match_word = -1, None for w in original_words: idx = index_of(w, haystack, lang=lang) - if idx > -1: - return idx, w - return -1, None + if idx > -1 and (match_pos == -1 or match_pos > idx): + match_pos, match_word = idx, w + return match_pos, match_word while True: text = unicode(c.selectedText()).rstrip('\0') - idx, word = find_word(text) + idx, word = find_first_word(text) if idx == -1: return False c.setPosition(c.anchor() + idx)