diff --git a/manual/edit.rst b/manual/edit.rst index 45bb93202b..3b0e71d079 100644 --- a/manual/edit.rst +++ b/manual/edit.rst @@ -802,7 +802,8 @@ The HTML editor has very sophisticated syntax highlighting. Features include: * The text inside bold, italic and heading tags is made bold/italic * As you move your cursor through the HTML, the matching HTML tags are highlighted, and you can jump to the opening or closing tag with the - keyboard shortcuts :kbd:`Ctrl+{` and :kbd:`Ctrl+}` + keyboard shortcuts :kbd:`Ctrl+{` and :kbd:`Ctrl+}`. Similarly, you + can select the contents of a tag with :kbd:`Ctrl+Alt+T`. * Invalid HTML is highlighted with a red underline * Spelling errors in the text inside HTML tags and attributes such as title are highlighted. The spell checking is language aware, based on the value diff --git a/src/calibre/gui2/tweak_book/editor/smarts/html.py b/src/calibre/gui2/tweak_book/editor/smarts/html.py index 91f031cd29..45c4af2915 100644 --- a/src/calibre/gui2/tweak_book/editor/smarts/html.py +++ b/src/calibre/gui2/tweak_book/editor/smarts/html.py @@ -352,6 +352,18 @@ class Smarts(NullSmarts): editor.setTextCursor(c) return True + def select_tag_contents(self, editor): + editor.highlighter.join() + start = self.last_matched_tag + end = self.last_matched_closing_tag + if start is None or end is None: + return False + c = editor.textCursor() + c.setPosition(start.start_block.position() + start.end_offset + 1) + c.setPosition(end.start_block.position() + end.start_offset, c.KeepAnchor) + editor.setTextCursor(c) + return True + def remove_tag(self, editor): editor.highlighter.join() if not self.last_matched_closing_tag and not self.last_matched_tag: @@ -662,6 +674,8 @@ class Smarts(NullSmarts): if int(mods & Qt.ControlModifier): if self.jump_to_enclosing_tag(editor, key == Qt.Key_BraceLeft): return True + if key == Qt.Key_T and int(ev.modifiers() & (Qt.ControlModifier | Qt.AltModifier)): + return self.select_tag_contents(editor) return False