From c615bf8b1cfc448c62cfb25ba018b1e58f8f054a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 16 Dec 2021 10:46:38 +0530 Subject: [PATCH] Edit book: Fix pressing F8 to jump to next misspelled word not working after last word in current file --- src/calibre/gui2/tweak_book/boss.py | 2 +- src/calibre/gui2/tweak_book/spell.py | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/tweak_book/boss.py b/src/calibre/gui2/tweak_book/boss.py index 573a7a486c..65aeb85e7c 100644 --- a/src/calibre/gui2/tweak_book/boss.py +++ b/src/calibre/gui2/tweak_book/boss.py @@ -1159,7 +1159,7 @@ class Boss(QObject): # Go to the next spelling error ed = self.gui.central.current_editor name = editor_name(ed) - find_next_error(ed, name, self.gui, self.show_editor, self.edit_file) + find_next_error(ed, name, self.gui, self.show_editor, self.edit_file, self.close_editor) def word_change_requested(self, w, new_word): if self.commit_all_editors_to_container(): diff --git a/src/calibre/gui2/tweak_book/spell.py b/src/calibre/gui2/tweak_book/spell.py index 5928c655dc..22d30faabe 100644 --- a/src/calibre/gui2/tweak_book/spell.py +++ b/src/calibre/gui2/tweak_book/spell.py @@ -1376,7 +1376,7 @@ def find_next(word, locations, current_editor, current_editor_name, return False -def find_next_error(current_editor, current_editor_name, gui_parent, show_editor, edit_file): +def find_next_error(current_editor, current_editor_name, gui_parent, show_editor, edit_file, close_editor): files = get_checkable_file_names(current_container())[0] if current_editor_name not in files: current_editor_name = None @@ -1391,12 +1391,18 @@ def find_next_error(current_editor, current_editor_name, gui_parent, show_editor from_cursor = True current_editor_name = None ed = editors.get(file_name, None) + needs_close = False if ed is None: edit_file(file_name) ed = editors[file_name] + needs_close = True + if hasattr(ed, 'highlighter'): + ed.highlighter.join() if ed.editor.find_next_spell_error(from_cursor=from_cursor): show_editor(file_name) return True + elif needs_close: + close_editor(file_name) return False # }}}