Edit book: Remove matching tag: Fix incorrect removal if the remove matching function is triggered in rapid succession

This commit is contained in:
Kovid Goyal 2018-08-21 22:33:04 +05:30
parent 7cb5118aba
commit 7f255f141d
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -352,9 +352,12 @@ class Smarts(NullSmarts):
def remove_tag(self, editor): def remove_tag(self, editor):
editor.highlighter.join() 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): def erase_tag(tag):
c = editor.textCursor()
c.setPosition(tag.start_block.position() + tag.start_offset) c.setPosition(tag.start_block.position() + tag.start_offset)
c.setPosition(tag.end_block.position() + tag.end_offset + 1, c.KeepAnchor) c.setPosition(tag.end_block.position() + tag.end_offset + 1, c.KeepAnchor)
c.removeSelectedText() c.removeSelectedText()
@ -363,6 +366,8 @@ class Smarts(NullSmarts):
erase_tag(self.last_matched_closing_tag) erase_tag(self.last_matched_closing_tag)
if self.last_matched_tag: if self.last_matched_tag:
erase_tag(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): def rename_block_tag(self, editor, new_name):
editor.highlighter.join() editor.highlighter.join()