mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
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)
This commit is contained in:
parent
6f5cd87990
commit
5b84dcb722
@ -675,13 +675,13 @@ class Smarts(NullSmarts):
|
|||||||
def find_text(self, pat, cursor):
|
def find_text(self, pat, cursor):
|
||||||
from calibre.gui2.tweak_book.text_search import find_text_in_chunks
|
from calibre.gui2.tweak_book.text_search import find_text_in_chunks
|
||||||
chunks = []
|
chunks = []
|
||||||
c = QTextCursor(cursor)
|
|
||||||
c.setPosition(0)
|
|
||||||
in_text = True
|
|
||||||
block = c.block()
|
|
||||||
|
|
||||||
cstart = min(cursor.position(), cursor.anchor())
|
cstart = min(cursor.position(), cursor.anchor())
|
||||||
cend = max(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):
|
def append(text, start):
|
||||||
after = start + len(text)
|
after = start + len(text)
|
||||||
@ -694,7 +694,7 @@ class Smarts(NullSmarts):
|
|||||||
text = text[extra:]
|
text = text[extra:]
|
||||||
chunks.append((text, start + max(extra, 0)))
|
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)
|
boundaries = sorted(block.userData().tags, key=get_offset)
|
||||||
if not boundaries:
|
if not boundaries:
|
||||||
# Add the whole line
|
# Add the whole line
|
||||||
|
@ -392,17 +392,8 @@ class TextEdit(PlainTextEdit):
|
|||||||
start, end = m.span()
|
start, end = m.span()
|
||||||
if start == end:
|
if start == end:
|
||||||
return False
|
return False
|
||||||
if wrap and not complete:
|
if reverse:
|
||||||
if reverse:
|
start, end = end, start
|
||||||
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
|
|
||||||
c.clearSelection()
|
c.clearSelection()
|
||||||
c.setPosition(start)
|
c.setPosition(start)
|
||||||
c.setPosition(end, c.KeepAnchor)
|
c.setPosition(end, c.KeepAnchor)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user