From 8d38de825e9721be0a324ae4774ee75b7523ee02 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 7 Sep 2016 12:55:05 +0530 Subject: [PATCH] Fix undo not working with sort css --- src/calibre/gui2/tweak_book/editor/text.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/tweak_book/editor/text.py b/src/calibre/gui2/tweak_book/editor/text.py index e101858247..eb26b02243 100644 --- a/src/calibre/gui2/tweak_book/editor/text.py +++ b/src/calibre/gui2/tweak_book/editor/text.py @@ -336,9 +336,16 @@ class TextEdit(PlainTextEdit): from calibre.gui2.dialogs.confirm_delete import confirm if confirm(_('Sorting CSS rules can in rare cases change the effective styles applied to the book.' ' Are you sure you want to proceed?'), 'edit-book-confirm-sort-css', parent=self, config_set=tprefs): + c = self.textCursor() + c.beginEditBlock() + c.movePosition(c.Start), c.movePosition(c.End, c.KeepAnchor) + text = unicode(c.selectedText()).replace(PARAGRAPH_SEPARATOR, '\n').rstrip('\0') from calibre.ebooks.oeb.polish.css import sort_sheet - text = sort_sheet(current_container(), self.toPlainText()).cssText - self.setPlainText(text) + text = sort_sheet(current_container(), text).cssText + c.insertText(text) + c.movePosition(c.Start) + c.endEditBlock() + self.setTextCursor(c) def find(self, pat, wrap=False, marked=False, complete=False, save_match=None): if marked: