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