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)