From 64141ab21f9843cc58bd7f130476c69cee8d07ec Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 1 Jun 2019 07:57:18 +0530 Subject: [PATCH] Edit book: Text search: Fix searching for a single character backwards not working --- src/calibre/gui2/tweak_book/editor/smarts/html.py | 4 +++- src/calibre/gui2/tweak_book/editor/text.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/tweak_book/editor/smarts/html.py b/src/calibre/gui2/tweak_book/editor/smarts/html.py index f14b855236..dde2c0cd31 100644 --- a/src/calibre/gui2/tweak_book/editor/smarts/html.py +++ b/src/calibre/gui2/tweak_book/editor/smarts/html.py @@ -733,12 +733,14 @@ class Smarts(NullSmarts): return 'complete_names', (names_type, doc_name, c.root), query - def find_text(self, pat, cursor): + def find_text(self, pat, cursor, reverse): from calibre.gui2.tweak_book.text_search import find_text_in_chunks chunks = [] cstart = min(cursor.position(), cursor.anchor()) cend = max(cursor.position(), cursor.anchor()) + if reverse: + cend -= 1 c = QTextCursor(cursor) c.setPosition(cstart) block = c.block() diff --git a/src/calibre/gui2/tweak_book/editor/text.py b/src/calibre/gui2/tweak_book/editor/text.py index e8eed6d278..9f3208dd1a 100644 --- a/src/calibre/gui2/tweak_book/editor/text.py +++ b/src/calibre/gui2/tweak_book/editor/text.py @@ -503,7 +503,7 @@ class TextEdit(PlainTextEdit): c.movePosition(pos, c.KeepAnchor) if hasattr(self.smarts, 'find_text'): self.highlighter.join() - found, start, end = self.smarts.find_text(pat, c) + found, start, end = self.smarts.find_text(pat, c, reverse) if not found: return False else: