From 95fc272b5baa336be75c3ba7f8e718bf62c847e0 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 24 Sep 2021 10:55:27 +0530 Subject: [PATCH] Edit book: When changing a paragraph to a heading if the cursor is adjacent to a paragraph tag but not inside any tags other than body, use the adjacent tag --- src/calibre/gui2/tweak_book/editor/smarts/html.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/calibre/gui2/tweak_book/editor/smarts/html.py b/src/calibre/gui2/tweak_book/editor/smarts/html.py index e7691b402c..8273129ef4 100644 --- a/src/calibre/gui2/tweak_book/editor/smarts/html.py +++ b/src/calibre/gui2/tweak_book/editor/smarts/html.py @@ -422,6 +422,14 @@ class Smarts(NullSmarts): tag = find_closest_containing_block_tag(block, offset) if tag is not None: + if tag.name == 'body': + ntag = find_closest_containing_block_tag(block, offset + 1) + if ntag is not None and ntag.name != 'body': + tag = ntag + elif offset > 0: + ntag = find_closest_containing_block_tag(block, offset - 1) + if ntag is not None and ntag.name != 'body': + tag = ntag closing_tag = find_closing_tag(tag) if closing_tag is None: return error_dialog(editor, _('Invalid HTML'), _(