mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-05-09 00:13:50 +02:00
Edit book: Allow removing the currently highlighted tag (while keeping its contents) by pressing Ctrl+>. You can also add a tool to do it via Preferences->Toolbars
This commit is contained in:
parent
81f1d44454
commit
668e208611
3 changed files with 21 additions and 0 deletions
|
|
@ -350,6 +350,20 @@ def jump_to_enclosing_tag(self, editor, start=True):
|
|||
editor.setTextCursor(c)
|
||||
return True
|
||||
|
||||
def remove_tag(self, editor):
|
||||
editor.highlighter.join()
|
||||
|
||||
def erase_tag(tag):
|
||||
c = editor.textCursor()
|
||||
c.setPosition(tag.start_block.position() + tag.start_offset)
|
||||
c.setPosition(tag.end_block.position() + tag.end_offset + 1, c.KeepAnchor)
|
||||
c.removeSelectedText()
|
||||
|
||||
if self.last_matched_closing_tag:
|
||||
erase_tag(self.last_matched_closing_tag)
|
||||
if self.last_matched_tag:
|
||||
erase_tag(self.last_matched_tag)
|
||||
|
||||
def rename_block_tag(self, editor, new_name):
|
||||
editor.highlighter.join()
|
||||
c = editor.textCursor()
|
||||
|
|
|
|||
|
|
@ -877,6 +877,10 @@ def insert_tag(self, tag):
|
|||
if hasattr(self.smarts, 'insert_tag'):
|
||||
self.smarts.insert_tag(self, tag)
|
||||
|
||||
def remove_tag(self):
|
||||
if hasattr(self.smarts, 'remove_tag'):
|
||||
self.smarts.remove_tag(self)
|
||||
|
||||
def keyPressEvent(self, ev):
|
||||
if ev.key() == Qt.Key_X and ev.modifiers() == Qt.AltModifier:
|
||||
if self.replace_possible_unicode_sequence():
|
||||
|
|
|
|||
|
|
@ -112,6 +112,9 @@ def reg(*args, **kw):
|
|||
ac = reg('code.png', _('Insert &tag'), ('insert_tag',), 'insert-tag', ('Ctrl+<'), _('Insert tag'), syntaxes=('html', 'xml'))
|
||||
ac.setToolTip(_('<h3>Insert tag</h3>Insert a tag, if some text is selected the tag will be inserted around the selected text'))
|
||||
|
||||
ac = reg('trash.png', _('Remove &tag'), ('remove_tag',), 'remove-tag', ('Ctrl+>'), _('Remove tag'), syntaxes=('html', 'xml'))
|
||||
ac.setToolTip(_('<h3>Remove tag</h3>Remove the currently highlighted tag'))
|
||||
|
||||
editor_toolbar_actions['html']['fix-html-current'] = actions['fix-html-current']
|
||||
for s in ('xml', 'html', 'css'):
|
||||
editor_toolbar_actions[s]['pretty-current'] = actions['pretty-current']
|
||||
|
|
|
|||
Loading…
Reference in a new issue