From ca5e5f4d144ab075e2e948072c8aa2c155531eee Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 6 Jan 2015 13:56:31 +0530 Subject: [PATCH] Refactor for reuse --- src/calibre/gui2/tweak_book/editor/text.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/tweak_book/editor/text.py b/src/calibre/gui2/tweak_book/editor/text.py index c42ad254a2..1c6e5ff3c2 100644 --- a/src/calibre/gui2/tweak_book/editor/text.py +++ b/src/calibre/gui2/tweak_book/editor/text.py @@ -31,6 +31,9 @@ from calibre.utils.titlecase import titlecase PARAGRAPH_SEPARATOR = '\u2029' +def selected_text_from_cursor(cursor): + return unicodedata.normalize('NFC', unicode(cursor.selectedText()).replace(PARAGRAPH_SEPARATOR, '\n').rstrip('\0')) + def get_highlighter(syntax): if syntax: try: @@ -111,7 +114,7 @@ class PlainTextEdit(QPlainTextEdit): self.textCursor().removeSelectedText() def selected_text_from_cursor(self, cursor): - return unicodedata.normalize('NFC', unicode(cursor.selectedText()).replace(PARAGRAPH_SEPARATOR, '\n').rstrip('\0')) + return selected_text_from_cursor(cursor) @property def selected_text(self):