Edit Book: Allow selecting the contents of a tag with Ctrl+Alt+t

This commit is contained in:
Kovid Goyal 2020-02-24 07:37:11 +05:30
parent 1088d699b7
commit 9e640df255
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 16 additions and 1 deletions

View File

@ -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 * 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 * 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 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 * Invalid HTML is highlighted with a red underline
* Spelling errors in the text inside HTML tags and attributes such as title * 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 are highlighted. The spell checking is language aware, based on the value

View File

@ -352,6 +352,18 @@ class Smarts(NullSmarts):
editor.setTextCursor(c) editor.setTextCursor(c)
return True 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): def remove_tag(self, editor):
editor.highlighter.join() editor.highlighter.join()
if not self.last_matched_closing_tag and not self.last_matched_tag: 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 int(mods & Qt.ControlModifier):
if self.jump_to_enclosing_tag(editor, key == Qt.Key_BraceLeft): if self.jump_to_enclosing_tag(editor, key == Qt.Key_BraceLeft):
return True return True
if key == Qt.Key_T and int(ev.modifiers() & (Qt.ControlModifier | Qt.AltModifier)):
return self.select_tag_contents(editor)
return False return False