diff --git a/src/calibre/gui2/tweak_book/editor/smarts/html.py b/src/calibre/gui2/tweak_book/editor/smarts/html.py index 9ee63c403c..854774587a 100644 --- a/src/calibre/gui2/tweak_book/editor/smarts/html.py +++ b/src/calibre/gui2/tweak_book/editor/smarts/html.py @@ -352,9 +352,12 @@ class Smarts(NullSmarts): def remove_tag(self, editor): editor.highlighter.join() + if not self.last_matched_closing_tag and not self.last_matched_tag: + return + c = editor.textCursor() + c.beginEditBlock() def erase_tag(tag): - c = editor.textCursor() c.setPosition(tag.start_block.position() + tag.start_offset) c.setPosition(tag.end_block.position() + tag.end_offset + 1, c.KeepAnchor) c.removeSelectedText() @@ -363,6 +366,8 @@ class Smarts(NullSmarts): erase_tag(self.last_matched_closing_tag) if self.last_matched_tag: erase_tag(self.last_matched_tag) + c.endEditBlock() + self.last_matched_tag = self.last_matched_closing_tag = None def rename_block_tag(self, editor, new_name): editor.highlighter.join()