From b4b4a6f179c28270d76b80e0b315d8980857aa14 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 1 Jul 2014 11:39:11 +0530 Subject: [PATCH] Edit Book: Fix a regression that caused syncing of the preview panel to the editor cursor position to not work when the cursor is positioned on a blank line in between two tag definitions --- .../gui2/tweak_book/editor/smart/html.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/calibre/gui2/tweak_book/editor/smart/html.py b/src/calibre/gui2/tweak_book/editor/smart/html.py index dea3dd86dd..cf63d1c14e 100644 --- a/src/calibre/gui2/tweak_book/editor/smart/html.py +++ b/src/calibre/gui2/tweak_book/editor/smart/html.py @@ -353,16 +353,23 @@ class HTMLSmarts(NullSmarts): block = cursor.block() offset = cursor.position() - block.position() nblock, boundary = next_tag_boundary(block, offset, forward=False) - if nblock is None: + if boundary is None: return None, None if boundary.is_start: # We are inside a tag, use this tag start_block, start_offset = nblock, boundary.offset else: - tag = find_closest_containing_tag(block, offset) - if tag is None: - return None, None - start_block, start_offset = tag.start_block, tag.start_offset + start_block = None + while start_block is None and block.isValid(): + ud = block.userData() + if ud is not None: + for boundary in reversed(ud.tags): + if boundary.is_start and not boundary.closing and boundary.offset <= offset: + start_block, start_offset = block, boundary.offset + break + block, offset = block.previous(), sys.maxint + if start_block is None: + return None, None sourceline = start_block.blockNumber() + 1 # blockNumber() is zero based ud = start_block.userData() if ud is None: