diff --git a/src/calibre/gui2/tweak_book/editor/text.py b/src/calibre/gui2/tweak_book/editor/text.py index e74035293c..feb2de578b 100644 --- a/src/calibre/gui2/tweak_book/editor/text.py +++ b/src/calibre/gui2/tweak_book/editor/text.py @@ -179,8 +179,14 @@ class TextEdit(PlainTextEdit): def insert_text(text): c = self.textCursor() - c.insertText(text) + c.insertText(unicodedata.normalize('NFC', text)) self.setTextCursor(c) + text = self.toPlainText() + if (ntext := unicodedata.normalize('NFC', text)) != text: + pos = c.position() + self.setPlainText(ntext) + c.setPosition(pos) + self.setTextCursor(c) self.ensureCursorVisible() def add_file(name, data, mt=None): diff --git a/src/calibre/gui2/tweak_book/widgets.py b/src/calibre/gui2/tweak_book/widgets.py index f4ba02680e..d090e7ec47 100644 --- a/src/calibre/gui2/tweak_book/widgets.py +++ b/src/calibre/gui2/tweak_book/widgets.py @@ -1274,6 +1274,9 @@ class PlainTextEdit(QPlainTextEdit): # {{{ def selected_text_from_cursor(self, cursor): return unicodedata.normalize('NFC', str(cursor.selectedText()).replace(PARAGRAPH_SEPARATOR, '\n').rstrip('\0')) + def paste(self): + super().paste() + @property def selected_text(self): return self.selected_text_from_cursor(self.textCursor())