mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix find next occurrence skipping some matches if a stem word maps to more than a single original word
This commit is contained in:
parent
294a17438c
commit
643d305548
@ -385,16 +385,17 @@ class TextEdit(PlainTextEdit):
|
|||||||
c.movePosition(c.Start)
|
c.movePosition(c.Start)
|
||||||
c.movePosition(c.End, c.KeepAnchor)
|
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:
|
for w in original_words:
|
||||||
idx = index_of(w, haystack, lang=lang)
|
idx = index_of(w, haystack, lang=lang)
|
||||||
if idx > -1:
|
if idx > -1 and (match_pos == -1 or match_pos > idx):
|
||||||
return idx, w
|
match_pos, match_word = idx, w
|
||||||
return -1, None
|
return match_pos, match_word
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
text = unicode(c.selectedText()).rstrip('\0')
|
text = unicode(c.selectedText()).rstrip('\0')
|
||||||
idx, word = find_word(text)
|
idx, word = find_first_word(text)
|
||||||
if idx == -1:
|
if idx == -1:
|
||||||
return False
|
return False
|
||||||
c.setPosition(c.anchor() + idx)
|
c.setPosition(c.anchor() + idx)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user