mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Only operate on normalized unicodedata in the editor
This commit is contained in:
parent
06aa59563d
commit
f1fc5598b0
@ -6,7 +6,7 @@ from __future__ import (unicode_literals, division, absolute_import,
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
import textwrap
|
||||
import textwrap, unicodedata
|
||||
from future_builtins import map
|
||||
|
||||
import regex
|
||||
@ -75,7 +75,7 @@ class TextEdit(QPlainTextEdit):
|
||||
|
||||
@property
|
||||
def selected_text(self):
|
||||
return unicode(self.textCursor().selectedText())
|
||||
return unicodedata.normalize('NFC', unicode(self.textCursor().selectedText()))
|
||||
|
||||
def sizeHint(self):
|
||||
return self.size_hint
|
||||
@ -125,7 +125,7 @@ class TextEdit(QPlainTextEdit):
|
||||
self.highlighter = {'html':HTMLHighlighter, 'css':CSSHighlighter, 'xml':XMLHighlighter}.get(syntax, SyntaxHighlighter)(self)
|
||||
self.highlighter.apply_theme(self.theme)
|
||||
self.highlighter.setDocument(self.document())
|
||||
self.setPlainText(text)
|
||||
self.setPlainText(unicodedata.normalize('NFC', text))
|
||||
if process_template and QPlainTextEdit.find(self, '%CURSOR%'):
|
||||
c = self.textCursor()
|
||||
c.insertText('')
|
||||
@ -136,7 +136,7 @@ class TextEdit(QPlainTextEdit):
|
||||
c.beginEditBlock()
|
||||
c.clearSelection()
|
||||
c.select(c.Document)
|
||||
c.insertText(text)
|
||||
c.insertText(unicodedata.normalize('NFC', text))
|
||||
c.endEditBlock()
|
||||
c.setPosition(min(pos, len(text)))
|
||||
self.setTextCursor(c)
|
||||
|
@ -6,6 +6,8 @@ from __future__ import (unicode_literals, division, absolute_import,
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
import unicodedata
|
||||
|
||||
from PyQt4.Qt import QMainWindow, Qt, QApplication, pyqtSignal
|
||||
|
||||
from calibre import xml_replace_entities
|
||||
@ -56,7 +58,7 @@ class Editor(QMainWindow):
|
||||
@dynamic_property
|
||||
def data(self):
|
||||
def fget(self):
|
||||
ans = unicode(self.editor.toPlainText())
|
||||
ans = self.get_raw_data()
|
||||
if self.syntax == 'html':
|
||||
ans = xml_replace_entities(ans)
|
||||
return ans.encode('utf-8')
|
||||
@ -68,7 +70,7 @@ class Editor(QMainWindow):
|
||||
self.editor.load_text(template, syntax=self.syntax, process_template=True)
|
||||
|
||||
def get_raw_data(self):
|
||||
return unicode(self.editor.toPlainText())
|
||||
return unicodedata.normalize('NFC', unicode(self.editor.toPlainText()))
|
||||
|
||||
def replace_data(self, raw, only_if_different=True):
|
||||
if isinstance(raw, bytes):
|
||||
|
Loading…
x
Reference in New Issue
Block a user