mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Edit book: Fix a regression in the previous release that caused Text search to sometimes not select matches correctly. Fixes #2034900 [Editor - Report: UnboundLocalError: local variable 'raw' referenced before assignment](https://bugs.launchpad.net/calibre/+bug/2034900)
This commit is contained in:
parent
ff3af3ac15
commit
8c3ff7e7aa
@ -503,20 +503,20 @@ class TextEdit(PlainTextEdit):
|
|||||||
if wrap and not complete:
|
if wrap and not complete:
|
||||||
pos = QTextCursor.MoveOperation.End if reverse else QTextCursor.MoveOperation.Start
|
pos = QTextCursor.MoveOperation.End if reverse else QTextCursor.MoveOperation.Start
|
||||||
c.movePosition(pos, QTextCursor.MoveMode.KeepAnchor)
|
c.movePosition(pos, QTextCursor.MoveMode.KeepAnchor)
|
||||||
raw = str(c.selectedText()).replace(PARAGRAPH_SEPARATOR, '\n').rstrip('\0')
|
|
||||||
if hasattr(self.smarts, 'find_text'):
|
if hasattr(self.smarts, 'find_text'):
|
||||||
self.highlighter.join()
|
self.highlighter.join()
|
||||||
found, start, end = self.smarts.find_text(pat, c, reverse)
|
found, start, end = self.smarts.find_text(pat, c, reverse)
|
||||||
if not found:
|
if not found:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
|
raw = str(c.selectedText()).replace(PARAGRAPH_SEPARATOR, '\n').rstrip('\0')
|
||||||
m = pat.search(raw)
|
m = pat.search(raw)
|
||||||
if m is None:
|
if m is None:
|
||||||
return False
|
return False
|
||||||
start, end = m.span()
|
start, end = m.span()
|
||||||
if start == end:
|
if start == end:
|
||||||
return False
|
return False
|
||||||
end = start + utf16_length(raw[start:end])
|
end = start + utf16_length(raw[start:end])
|
||||||
if reverse:
|
if reverse:
|
||||||
start, end = end, start
|
start, end = end, start
|
||||||
c.clearSelection()
|
c.clearSelection()
|
||||||
|
@ -17,6 +17,7 @@ from calibre.gui2.tweak_book.search import (
|
|||||||
from calibre.gui2.widgets import BusyCursor
|
from calibre.gui2.widgets import BusyCursor
|
||||||
from calibre.gui2.widgets2 import HistoryComboBox
|
from calibre.gui2.widgets2 import HistoryComboBox
|
||||||
from calibre.startup import connect_lambda
|
from calibre.startup import connect_lambda
|
||||||
|
from calibre.utils.icu import utf16_length
|
||||||
from polyglot.builtins import error_message, iteritems
|
from polyglot.builtins import error_message, iteritems
|
||||||
|
|
||||||
# UI {{{
|
# UI {{{
|
||||||
@ -219,7 +220,7 @@ def find_text_in_chunks(pat, chunks):
|
|||||||
start_pos = chunk_start + (start - offset)
|
start_pos = chunk_start + (start - offset)
|
||||||
if start_pos is not None:
|
if start_pos is not None:
|
||||||
if contains(clen, after-1):
|
if contains(clen, after-1):
|
||||||
end_pos = chunk_start + (after - offset)
|
end_pos = chunk_start + utf16_length(chunk[:after-offset])
|
||||||
return start_pos, end_pos
|
return start_pos, end_pos
|
||||||
offset += clen
|
offset += clen
|
||||||
if offset > after:
|
if offset > after:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user