Edit book: Fix searching for non-BMP unicode characters highlighting only half the character

This commit is contained in:
Kovid Goyal 2023-08-22 09:13:06 +05:30
parent 181dc063df
commit 745dc0c72c
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -35,7 +35,7 @@ from calibre.gui2.tweak_book.editor.themes import (
from calibre.gui2.tweak_book.widgets import PARAGRAPH_SEPARATOR, PlainTextEdit from calibre.gui2.tweak_book.widgets import PARAGRAPH_SEPARATOR, PlainTextEdit
from calibre.spell.break_iterator import index_of from calibre.spell.break_iterator import index_of
from calibre.utils.icu import ( from calibre.utils.icu import (
capitalize, lower, safe_chr, string_length, swapcase, upper capitalize, lower, safe_chr, string_length, swapcase, upper, utf16_length
) )
from calibre.utils.img import image_to_data from calibre.utils.img import image_to_data
from calibre.utils.titlecase import titlecase from calibre.utils.titlecase import titlecase
@ -470,6 +470,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])
if wrap and not complete: if wrap and not complete:
if reverse: if reverse:
textpos = c.anchor() textpos = c.anchor()
@ -515,6 +516,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])
if reverse: if reverse:
start, end = end, start start, end = end, start
c.clearSelection() c.clearSelection()