From 7effa7c79ff11c19c6fe3beb95d9b81a32303bfe Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 8 Jan 2015 06:31:13 +0530 Subject: [PATCH] Expanding snippets now works --- src/calibre/gui2/tweak_book/editor/snippets.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/tweak_book/editor/snippets.py b/src/calibre/gui2/tweak_book/editor/snippets.py index c790ffef19..fa99cb9896 100644 --- a/src/calibre/gui2/tweak_book/editor/snippets.py +++ b/src/calibre/gui2/tweak_book/editor/snippets.py @@ -182,8 +182,9 @@ class EditorTabStop(object): class Template(list): def __new__(self, tab_stops): - self = list.__new__(self, tab_stops) + self = list.__new__(self) self.left_most_cursor = self.right_most_cursor = None + self.extend(tab_stops) for c in self: if self.left_most_cursor is None or self.left_most_cursor.position() > c.left.position(): self.left_most_cursor = c.left @@ -234,7 +235,9 @@ 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.itervalues()] + other = QTextCursor(c) + other.setPosition(left) + editor_tab_stops = [EditorTabStop(other, ts) for ts in tab_stops.itervalues()] if selected_text: for ts in editor_tab_stops: