From 4f5469e42d9da2afead09dda9078c463c5b4c956 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 8 Dec 2013 21:37:43 +0530 Subject: [PATCH] Fix non breaking spaces being stripped out during save --- src/calibre/gui2/tweak_book/editor/text.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/calibre/gui2/tweak_book/editor/text.py b/src/calibre/gui2/tweak_book/editor/text.py index de8e817f0e..9e0a7efc5a 100644 --- a/src/calibre/gui2/tweak_book/editor/text.py +++ b/src/calibre/gui2/tweak_book/editor/text.py @@ -124,6 +124,16 @@ class TextEdit(QPlainTextEdit): self.highlight_cursor_line() # }}} + def toPlainText(self): + # QPlainTextEdit's toPlainText implementation replaces nbsp with normal + # space, so we re-implement it using QTextCursor, which does not do + # that + c = self.textCursor() + c.clearSelection() + c.movePosition(c.Start) + c.movePosition(c.End, c.KeepAnchor) + return c.selectedText().replace(PARAGRAPH_SEPARATOR, '\n') + def load_text(self, text, syntax='html', process_template=False): self.highlighter = {'html':HTMLHighlighter, 'css':CSSHighlighter, 'xml':XMLHighlighter}.get(syntax, SyntaxHighlighter)(self) self.highlighter.apply_theme(self.theme)