mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Edit Book: Automatically complete the closing tag in HTML/XML files when typing </
This commit is contained in:
parent
690b84ce12
commit
16ca5d9c3c
@ -580,6 +580,9 @@ class Smarts(NullSmarts):
|
|||||||
text = text[:-editor.tw] + '</'
|
text = text[:-editor.tw] + '</'
|
||||||
cursor.insertText(text)
|
cursor.insertText(text)
|
||||||
editor.setTextCursor(cursor)
|
editor.setTextCursor(cursor)
|
||||||
|
self.auto_close_tag(editor)
|
||||||
|
return True
|
||||||
|
if self.auto_close_tag(editor):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if key == Qt.Key_Home and smart_home(editor, ev):
|
if key == Qt.Key_Home and smart_home(editor, ev):
|
||||||
@ -607,6 +610,16 @@ class Smarts(NullSmarts):
|
|||||||
c.insertText(repl)
|
c.insertText(repl)
|
||||||
editor.setTextCursor(c)
|
editor.setTextCursor(c)
|
||||||
|
|
||||||
|
def auto_close_tag(self, editor):
|
||||||
|
c = editor.textCursor()
|
||||||
|
block, offset = c.block(), c.positionInBlock()
|
||||||
|
tag = find_closest_containing_tag(block, offset, max_tags=4000)
|
||||||
|
if tag is None:
|
||||||
|
return False
|
||||||
|
c.insertText('/%s>' % tag.name)
|
||||||
|
editor.setTextCursor(c)
|
||||||
|
return True
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
from calibre.gui2.tweak_book.editor.widget import launch_editor
|
from calibre.gui2.tweak_book.editor.widget import launch_editor
|
||||||
launch_editor('''\
|
launch_editor('''\
|
||||||
|
Loading…
x
Reference in New Issue
Block a user