Change the trigger shortcut for snippets to Ctrl+J and Ctrl+Tab is often used by the OS

This commit is contained in:
Kovid Goyal 2015-01-09 17:12:55 +05:30
parent 96856c14e1
commit 35f9614f19
3 changed files with 7 additions and 4 deletions

View File

@ -1,7 +1,7 @@
Snippets
========================
.. |ct| replace:: ``Ctrl+Tab``
.. |ct| replace:: ``Control+J``
The calibre editor supports *snippets*. A snippet is a
piece of text that is either re-used often or contains a lot of redundant

View File

@ -16,6 +16,7 @@ from PyQt5.Qt import (
QToolButton, QIcon, QHBoxLayout, QPushButton, QListWidget, QListWidgetItem,
QGridLayout, QPlainTextEdit, QLabel, QFrame, QDialog, QDialogButtonBox)
from calibre.constants import isosx
from calibre.gui2 import error_dialog
from calibre.gui2.tweak_book.editor import all_text_syntaxes
from calibre.gui2.tweak_book.editor.smarts.utils import get_text_before_cursor
@ -25,6 +26,8 @@ from calibre.utils.icu import string_length as strlen
from calibre.utils.localization import localize_user_manual_link
string_length = lambda x: strlen(unicode(x)) # Needed on narrow python builds, as subclasses of unicode dont work
KEY = Qt.Key_J
MODIFIER = Qt.META if isosx else Qt.CTRL
SnipKey = namedtuple('SnipKey', 'trigger syntaxes')
def snip_key(trigger, *syntaxes):
@ -382,7 +385,7 @@ class SnippetManager(QObject):
def handle_key_press(self, ev):
editor = self.parent()
if ev.key() == Qt.Key_Tab and ev.modifiers() & Qt.CTRL:
if ev.key() == KEY and ev.modifiers() & MODIFIER:
at = self.get_active_template(editor.textCursor())
if at is not None:
if at.jump_to_next(editor) is None:

View File

@ -26,7 +26,7 @@ from calibre.gui2.tweak_book import tprefs, editors, current_container
from calibre.gui2.tweak_book.function_replace import (
FunctionBox, functions as replace_functions, FunctionEditor, remove_function, Function)
from calibre.gui2.tweak_book.widgets import BusyCursor
from calibre.gui2.tweak_book.editor.snippets import find_matching_snip, parse_template, string_length, SnippetTextEdit
from calibre.gui2.tweak_book.editor.snippets import find_matching_snip, parse_template, string_length, SnippetTextEdit, MODIFIER, KEY
from calibre.utils.icu import primary_contains
@ -88,7 +88,7 @@ class HistoryBox(HistoryComboBox):
self.ignore_snip_expansion = False
def event(self, ev):
if ev.type() in (ev.ShortcutOverride, ev.KeyPress) and ev.key() == Qt.Key_Tab and ev.modifiers() & Qt.CTRL:
if ev.type() in (ev.ShortcutOverride, ev.KeyPress) and ev.key() == KEY and ev.modifiers() & MODIFIER:
if not self.ignore_snip_expansion:
self.ignore_snip_expansion = True
expand_template(self.lineEdit())