From 8cc82b6c8fadc168c3e81835020693d57d58afd9 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 4 Feb 2015 08:53:29 +0530 Subject: [PATCH] Edit Book: Do not autocomplete the closing tag wen typing the / key inside an existing tag. Fixes #1417700 [Editor: Auto-Completion of HTML is screwing up the HTML](https://bugs.launchpad.net/calibre/+bug/1417700) --- src/calibre/gui2/tweak_book/editor/smarts/html.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/calibre/gui2/tweak_book/editor/smarts/html.py b/src/calibre/gui2/tweak_book/editor/smarts/html.py index f548d7bb01..a6cd3e950c 100644 --- a/src/calibre/gui2/tweak_book/editor/smarts/html.py +++ b/src/calibre/gui2/tweak_book/editor/smarts/html.py @@ -619,8 +619,20 @@ class Smarts(NullSmarts): editor.setTextCursor(c) def auto_close_tag(self, editor): + + def check_if_in_tag(block, offset=0): + if block.isValid(): + text = block.text() + close_pos = text.find('>', offset) + open_pos = text.find('<', offset) + if (close_pos > -1 and open_pos == -1) or (close_pos < open_pos): + return True + return False + c = editor.textCursor() block, offset = c.block(), c.positionInBlock() + if check_if_in_tag(block, offset) or check_if_in_tag(block.next()): + return False tag = find_closest_containing_tag(block, offset - 1, max_tags=4000) if tag is None: return False