From 58812876718ec343cbdb88d20dcb413e083b40fd Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 27 Jul 2014 07:13:46 +0530 Subject: [PATCH] Edit Book: Fix incorrect results when running replace all on marked text and more than one replacement is made. Fixes #1348941 [When applying the command Replace all with marked text, error happens](https://bugs.launchpad.net/calibre/+bug/1348941) --- src/calibre/gui2/tweak_book/editor/text.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/tweak_book/editor/text.py b/src/calibre/gui2/tweak_book/editor/text.py index 1a93fb8a1c..6da5919a31 100644 --- a/src/calibre/gui2/tweak_book/editor/text.py +++ b/src/calibre/gui2/tweak_book/editor/text.py @@ -348,9 +348,10 @@ class TextEdit(PlainTextEdit): else: raw, count = pat.subn(template, raw) if count > 0: - c.setKeepPositionOnInsert(True) + start_pos = min(c.anchor(), c.position()) c.insertText(raw) - c.setKeepPositionOnInsert(False) + end_pos = max(c.anchor(), c.position()) + c.setPosition(start_pos), c.setPosition(end_pos, c.KeepAnchor) self.update_extra_selections() return count