Fix #2051207 [Editor: Insert Link produces two undo actions](https://bugs.launchpad.net/calibre/+bug/2051207)

This commit is contained in:
Kovid Goyal 2024-02-05 14:36:21 +05:30
parent d38baa022c
commit 39505b9d55
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -480,6 +480,7 @@ class Smarts(NullSmarts):
template = template.replace('_TEXT_', text or '')
editor.highlighter.join()
c = editor.textCursor()
c.beginEditBlock()
if c.hasSelection():
c.insertText('') # delete any existing selected text
ensure_not_within_tag_definition(c)
@ -487,6 +488,7 @@ class Smarts(NullSmarts):
c.insertText(template)
c.setPosition(p) # ensure cursor is positioned inside the newly created tag
editor.setTextCursor(c)
c.endEditBlock()
def insert_tag(self, editor, name):
m = re.match(r'[a-zA-Z0-9:-]+', name)