mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-07 09:01:38 -04:00
Edit book: Fix searching marking incorrect text in the presence of non-BMP unicode characters. Fixes #2075970 [regex does not properly select match](https://bugs.launchpad.net/calibre/+bug/2075970)
This commit is contained in:
parent
9f76ddb56f
commit
da187adea6
@ -50,6 +50,13 @@ from calibre.utils.titlecase import titlecase
|
|||||||
from polyglot.builtins import as_unicode
|
from polyglot.builtins import as_unicode
|
||||||
|
|
||||||
|
|
||||||
|
def adjust_for_non_bmp_chars(raw: str, start: int, end: int) -> tuple[int, int]:
|
||||||
|
adjusted_start = utf16_length(raw[:start])
|
||||||
|
end = adjusted_start + utf16_length(raw[start:end])
|
||||||
|
start = adjusted_start
|
||||||
|
return start, end
|
||||||
|
|
||||||
|
|
||||||
def get_highlighter(syntax):
|
def get_highlighter(syntax):
|
||||||
if syntax:
|
if syntax:
|
||||||
try:
|
try:
|
||||||
@ -395,6 +402,7 @@ class TextEdit(PlainTextEdit):
|
|||||||
start, end = m.span()
|
start, end = m.span()
|
||||||
if start == end:
|
if start == end:
|
||||||
return False
|
return False
|
||||||
|
start, end = adjust_for_non_bmp_chars(raw, start, end)
|
||||||
if wrap:
|
if wrap:
|
||||||
if reverse:
|
if reverse:
|
||||||
textpos = c.anchor()
|
textpos = c.anchor()
|
||||||
@ -486,7 +494,7 @@ class TextEdit(PlainTextEdit):
|
|||||||
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])
|
start, end = adjust_for_non_bmp_chars(raw, start, end)
|
||||||
if wrap and not complete:
|
if wrap and not complete:
|
||||||
if reverse:
|
if reverse:
|
||||||
textpos = c.anchor()
|
textpos = c.anchor()
|
||||||
@ -532,7 +540,7 @@ class TextEdit(PlainTextEdit):
|
|||||||
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])
|
start, end = adjust_for_non_bmp_chars(raw, start, end)
|
||||||
if reverse:
|
if reverse:
|
||||||
start, end = end, start
|
start, end = end, start
|
||||||
c.clearSelection()
|
c.clearSelection()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user