From a31474804f91d0eb869f2ea37878e9336aa3da5f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 19 Sep 2019 08:06:26 +0530 Subject: [PATCH] When inserting a link, preserve the currently selected text, if any --- src/calibre/gui2/comments_editor.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/comments_editor.py b/src/calibre/gui2/comments_editor.py index 0f8f5e7194..87650f6318 100644 --- a/src/calibre/gui2/comments_editor.py +++ b/src/calibre/gui2/comments_editor.py @@ -539,6 +539,7 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{ url = unicode_type(url.toString(NO_URL_FORMATTING)) self.focus_self() with self.editing_cursor() as c: + selected_text = c.selectedText() if is_image: c.insertImage(url) else: @@ -550,7 +551,7 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{ fmt.setForeground(QBrush(QColor('blue'))) prev_fmt = c.charFormat() c.mergeCharFormat(fmt) - c.insertText(url) + c.insertText(selected_text or url) c.setCharFormat(prev_fmt) else: error_dialog(self, _('Invalid URL'),