mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Wire up the snippet manager
Its implementation is not yet complete
This commit is contained in:
parent
19be8cd0c0
commit
6c6dce47a1
@ -23,7 +23,7 @@ SnipKey = namedtuple('SnipKey', 'trigger syntaxes')
|
||||
def snip_key(trigger, *syntaxes):
|
||||
if '*' in syntaxes:
|
||||
syntaxes = all_text_syntaxes
|
||||
return SnipKey(trigger, frozenset(*syntaxes))
|
||||
return SnipKey(trigger, frozenset(syntaxes))
|
||||
|
||||
builtin_snippets = { # {{{
|
||||
snip_key('<<', 'html', 'xml'): {
|
||||
@ -234,7 +234,7 @@ def expand_template(editor, trigger, template, selected_text=''):
|
||||
left = right - string_length(trigger)
|
||||
text, tab_stops = parse_template(template)
|
||||
c.setPosition(left), c.setPosition(right, c.KeepAnchor), c.insertText(text)
|
||||
editor_tab_stops = [EditorTabStop(c, ts) for ts in tab_stops]
|
||||
editor_tab_stops = [EditorTabStop(c, ts) for ts in tab_stops.itervalues()]
|
||||
|
||||
if selected_text:
|
||||
for ts in editor_tab_stops:
|
||||
@ -273,10 +273,10 @@ class SnippetManager(QObject):
|
||||
self.active_templates.remove(template)
|
||||
return at
|
||||
|
||||
def handle_keypress(self, ev):
|
||||
def handle_key_press(self, ev):
|
||||
editor = self.parent()
|
||||
if ev.key() == Qt.Key_Tab and ev.modifiers() & Qt.CTRL:
|
||||
at = self.get_active_template(editor.cursor())
|
||||
at = self.get_active_template(editor.textCursor())
|
||||
if at is not None:
|
||||
if at.jump_to_next(editor) is None:
|
||||
self.active_templates.remove(at)
|
@ -25,6 +25,7 @@ from calibre.gui2.tweak_book.editor import (
|
||||
from calibre.gui2.tweak_book.editor.themes import get_theme, theme_color, theme_format
|
||||
from calibre.gui2.tweak_book.editor.syntax.base import SyntaxHighlighter
|
||||
from calibre.gui2.tweak_book.editor.smarts import NullSmarts
|
||||
from calibre.gui2.tweak_book.editor.snippets import SnippetManager
|
||||
from calibre.spell.break_iterator import index_of
|
||||
from calibre.utils.icu import safe_chr, string_length, capitalize, upper, lower, swapcase
|
||||
from calibre.utils.titlecase import titlecase
|
||||
@ -142,6 +143,7 @@ class TextEdit(PlainTextEdit):
|
||||
|
||||
def __init__(self, parent=None, expected_geometry=(100, 50)):
|
||||
PlainTextEdit.__init__(self, parent)
|
||||
self.snippet_manager = SnippetManager(self)
|
||||
self.completion_popup = CompletionPopup(self)
|
||||
self.request_completion = self.completion_doc_name = None
|
||||
self.clear_completion_cache_timer = t = QTimer(self)
|
||||
@ -783,6 +785,8 @@ class TextEdit(PlainTextEdit):
|
||||
# https://bugreports.qt-project.org/browse/QTBUG-36281
|
||||
ev.setAccepted(False)
|
||||
return
|
||||
if self.snippet_manager.handle_key_press(ev):
|
||||
return
|
||||
if self.smarts.handle_key_press(ev, self):
|
||||
self.handle_keypress_completion(ev)
|
||||
return
|
||||
|
Loading…
x
Reference in New Issue
Block a user