From 219a1572f6c9b41068e7ff8fd2a98c5d198be3a5 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 7 Feb 2024 07:20:42 +0530 Subject: [PATCH] Edit book: When wrapping selected text in a tag, preserve the selection after wrapping. Fixes #2050100 [small problem in edit-mode](https://bugs.launchpad.net/calibre/+bug/2050100) --- src/calibre/gui2/tweak_book/editor/smarts/html.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/calibre/gui2/tweak_book/editor/smarts/html.py b/src/calibre/gui2/tweak_book/editor/smarts/html.py index 7c897cc832..b83bdaf94f 100644 --- a/src/calibre/gui2/tweak_book/editor/smarts/html.py +++ b/src/calibre/gui2/tweak_book/editor/smarts/html.py @@ -500,8 +500,10 @@ class Smarts(NullSmarts): text = self.get_smart_selection(editor, update=True) c = editor.textCursor() pos = min(c.position(), c.anchor()) + sellen = abs(c.position() - c.anchor()) c.insertText(f'{opent}{text}{close}') c.setPosition(pos + len(opent)) + c.setPosition(c.position() + sellen, QTextCursor.MoveMode.KeepAnchor) editor.setTextCursor(c) def verify_for_spellcheck(self, cursor, highlighter):