mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-30 23:00:21 -04:00
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:
parent
5ab3d72ed7
commit
8ed750302a
@ -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):
|
||||||
|
@ -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())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user