From 2d7330d2a9df882d6bbd0246f1a6ef8453c57139 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 18 Apr 2014 22:10:49 +0530 Subject: [PATCH] Edit Book: Fix the Show next occurrence button in the spell check dialog not always working --- src/calibre/gui2/tweak_book/editor/text.py | 6 +++--- src/calibre/gui2/tweak_book/editor/widget.py | 4 ++-- src/calibre/gui2/tweak_book/spell.py | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/calibre/gui2/tweak_book/editor/text.py b/src/calibre/gui2/tweak_book/editor/text.py index 5c32cf7f31..cd121e44a6 100644 --- a/src/calibre/gui2/tweak_book/editor/text.py +++ b/src/calibre/gui2/tweak_book/editor/text.py @@ -378,7 +378,7 @@ class TextEdit(PlainTextEdit): self.saved_matches[save_match] = (pat, m) return True - def find_word_in_line(self, word, lang, lnum, from_cursor=True): + def find_word_from_line(self, word, lang, lnum, from_cursor=True): c = self.textCursor() c.setPosition(c.position()) if not from_cursor or c.blockNumber() != lnum - 1: @@ -386,11 +386,11 @@ class TextEdit(PlainTextEdit): c.movePosition(c.Start) c.movePosition(c.NextBlock, n=lnum - 1) c.movePosition(c.StartOfLine) - c.movePosition(c.EndOfBlock, c.KeepAnchor) offset = c.block().position() + c.movePosition(c.End, c.KeepAnchor) else: offset = c.block().position() + c.positionInBlock() - c.movePosition(c.EndOfBlock, c.KeepAnchor) + c.movePosition(c.End, c.KeepAnchor) text = unicode(c.selectedText()).rstrip('\0') idx = index_of(word, text, lang=lang) if idx == -1: diff --git a/src/calibre/gui2/tweak_book/editor/widget.py b/src/calibre/gui2/tweak_book/editor/widget.py index 232a2f0f8f..d60f993701 100644 --- a/src/calibre/gui2/tweak_book/editor/widget.py +++ b/src/calibre/gui2/tweak_book/editor/widget.py @@ -189,8 +189,8 @@ class Editor(QMainWindow): def find(self, *args, **kwargs): return self.editor.find(*args, **kwargs) - def find_word_in_line(self, *args, **kwargs): - return self.editor.find_word_in_line(*args, **kwargs) + def find_word_from_line(self, *args, **kwargs): + return self.editor.find_word_from_line(*args, **kwargs) def replace(self, *args, **kwargs): return self.editor.replace(*args, **kwargs) diff --git a/src/calibre/gui2/tweak_book/spell.py b/src/calibre/gui2/tweak_book/spell.py index 37d2209603..abe0fe835a 100644 --- a/src/calibre/gui2/tweak_book/spell.py +++ b/src/calibre/gui2/tweak_book/spell.py @@ -1046,7 +1046,7 @@ def find_next(word, locations, current_editor, current_editor_name, idx = lfiles.index(current_editor_name) before, after = lfiles[:idx], lfiles[idx+1:] lfiles = after + before + [current_editor_name] - lnum = current_editor.current_line + lnum = current_editor.current_line + 1 start_locations = [l for l in files[current_editor_name] if l.sourceline >= lnum] locations = list(start_locations) for fname in lfiles: @@ -1058,7 +1058,7 @@ def find_next(word, locations, current_editor, current_editor_name, if ed is None: edit_file(location.file_name) ed = editors[location.file_name] - if ed.find_word_in_line(location.original_word, word[1].langcode, location.sourceline, from_cursor=location in start_locations): + if ed.find_word_from_line(location.original_word, word[1].langcode, location.sourceline, from_cursor=location in start_locations): show_editor(location.file_name) return True return False