From 5b84dcb7224db1399df15ec9444d6b112da498e5 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 4 Jun 2016 09:05:41 +0530 Subject: [PATCH] Edit Book: Fix a bug in the new text search facility that could cause searches to fail when searching from the current cursor position instead of the top of the file. Fixes #1588778 [Search with tags](https://bugs.launchpad.net/calibre/+bug/1588778) --- src/calibre/gui2/tweak_book/editor/smarts/html.py | 10 +++++----- src/calibre/gui2/tweak_book/editor/text.py | 13 ++----------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/calibre/gui2/tweak_book/editor/smarts/html.py b/src/calibre/gui2/tweak_book/editor/smarts/html.py index b81ff37c30..edabbb1ef1 100644 --- a/src/calibre/gui2/tweak_book/editor/smarts/html.py +++ b/src/calibre/gui2/tweak_book/editor/smarts/html.py @@ -675,13 +675,13 @@ class Smarts(NullSmarts): def find_text(self, pat, cursor): from calibre.gui2.tweak_book.text_search import find_text_in_chunks chunks = [] - c = QTextCursor(cursor) - c.setPosition(0) - in_text = True - block = c.block() cstart = min(cursor.position(), cursor.anchor()) cend = max(cursor.position(), cursor.anchor()) + c = QTextCursor(cursor) + c.setPosition(cstart) + block = c.block() + in_text = find_tag_definition(block, 0)[0] is None def append(text, start): after = start + len(text) @@ -694,7 +694,7 @@ class Smarts(NullSmarts): text = text[extra:] chunks.append((text, start + max(extra, 0))) - while block.isValid() and block.position() <= cend and block.position() + block.length() > cstart: + while block.isValid() and block.position() <= cend: boundaries = sorted(block.userData().tags, key=get_offset) if not boundaries: # Add the whole line diff --git a/src/calibre/gui2/tweak_book/editor/text.py b/src/calibre/gui2/tweak_book/editor/text.py index e5e7b06e18..9176992b35 100644 --- a/src/calibre/gui2/tweak_book/editor/text.py +++ b/src/calibre/gui2/tweak_book/editor/text.py @@ -392,17 +392,8 @@ class TextEdit(PlainTextEdit): start, end = m.span() if start == end: return False - if wrap and not complete: - if reverse: - textpos = c.anchor() - start, end = textpos + end, textpos + start - else: - if reverse: - # Put the cursor at the start of the match - start, end = end, start - else: - textpos = c.anchor() - start, end = textpos + start, textpos + end + if reverse: + start, end = end, start c.clearSelection() c.setPosition(start) c.setPosition(end, c.KeepAnchor)