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)

This commit is contained in:
Kovid Goyal 2014-07-27 07:13:46 +05:30
parent 3eb87c29f9
commit 5881287671

View File

@ -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