Edit book: When pasting text from the clipboard ensure it is normalized to NFC form. Fixes #2099740 [Pasting into Editor breaks spellchecking](https://bugs.launchpad.net/calibre/+bug/2099740)

This commit is contained in:
Kovid Goyal 2025-08-21 09:32:44 +05:30
parent 5ab3d72ed7
commit 8ed750302a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 10 additions and 1 deletions

View File

@ -179,8 +179,14 @@ class TextEdit(PlainTextEdit):
def insert_text(text): def insert_text(text):
c = self.textCursor() c = self.textCursor()
c.insertText(text) c.insertText(unicodedata.normalize('NFC', text))
self.setTextCursor(c) 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() self.ensureCursorVisible()
def add_file(name, data, mt=None): def add_file(name, data, mt=None):

View File

@ -1274,6 +1274,9 @@ class PlainTextEdit(QPlainTextEdit): # {{{
def selected_text_from_cursor(self, cursor): def selected_text_from_cursor(self, cursor):
return unicodedata.normalize('NFC', str(cursor.selectedText()).replace(PARAGRAPH_SEPARATOR, '\n').rstrip('\0')) return unicodedata.normalize('NFC', str(cursor.selectedText()).replace(PARAGRAPH_SEPARATOR, '\n').rstrip('\0'))
def paste(self):
super().paste()
@property @property
def selected_text(self): def selected_text(self):
return self.selected_text_from_cursor(self.textCursor()) return self.selected_text_from_cursor(self.textCursor())