From 745dc0c72cc11b6c7ad4bb5c42f210a1129f00ab Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 22 Aug 2023 09:13:06 +0530 Subject: [PATCH] Edit book: Fix searching for non-BMP unicode characters highlighting only half the character --- src/calibre/gui2/tweak_book/editor/text.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/tweak_book/editor/text.py b/src/calibre/gui2/tweak_book/editor/text.py index 7c51e19bc7..d8439319fb 100644 --- a/src/calibre/gui2/tweak_book/editor/text.py +++ b/src/calibre/gui2/tweak_book/editor/text.py @@ -35,7 +35,7 @@ from calibre.gui2.tweak_book.editor.themes import ( from calibre.gui2.tweak_book.widgets import PARAGRAPH_SEPARATOR, PlainTextEdit from calibre.spell.break_iterator import index_of 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.titlecase import titlecase @@ -470,6 +470,7 @@ class TextEdit(PlainTextEdit): start, end = m.span() if start == end: return False + end = start + utf16_length(raw[start:end]) if wrap and not complete: if reverse: textpos = c.anchor() @@ -515,6 +516,7 @@ class TextEdit(PlainTextEdit): start, end = m.span() if start == end: return False + end = start + utf16_length(raw[start:end]) if reverse: start, end = end, start c.clearSelection()