diff --git a/resources/default_tweaks.py b/resources/default_tweaks.py index 32aeba9122..f1abfbe7ea 100644 --- a/resources/default_tweaks.py +++ b/resources/default_tweaks.py @@ -30,6 +30,13 @@ defaults. series_index_auto_increment = 'next' +# Should the completion separator be append +# to the end of the completed text to +# automatically begin a new completion operation. +# Can be either True or False +completer_append_separator = False + + # The algorithm used to copy author to author_sort # Possible values are: # invert: use "fn ln" -> "ln, fn" (the original algorithm) diff --git a/src/calibre/gui2/complete.py b/src/calibre/gui2/complete.py index f589b30679..a013065690 100644 --- a/src/calibre/gui2/complete.py +++ b/src/calibre/gui2/complete.py @@ -10,6 +10,7 @@ from PyQt4.Qt import QLineEdit, QListView, QAbstractListModel, Qt, QTimer, \ QApplication, QPoint, QItemDelegate, QStyleOptionViewItem, \ QStyle, QEvent, pyqtSignal +from calibre.utils.config import tweaks from calibre.utils.icu import sort_key, lower from calibre.gui2 import NONE from calibre.gui2.widgets import EnComboBox @@ -231,12 +232,18 @@ class MultiCompleteLineEdit(QLineEdit): cursor_pos = self.cursorPosition() before_text = unicode(self.text())[:cursor_pos] after_text = unicode(self.text())[cursor_pos:] - after_parts = after_text.split(self.sep) - if len(after_parts) < 3 and not after_parts[-1].strip(): - after_text = u'' prefix_len = len(before_text.split(self.sep)[-1].lstrip()) - return prefix_len, \ - before_text[:cursor_pos - prefix_len] + text + after_text + if tweaks['completer_append_separator']: + prefix_len = len(before_text.split(self.sep)[-1].lstrip()) + completed_text = before_text[:cursor_pos - prefix_len] + text + self.sep + ' ' + after_text + prefix_len = prefix_len - len(self.sep) - 1 + if prefix_len < 0: + prefix_len = 0 + else: + prefix_len = len(before_text.split(self.sep)[-1].lstrip()) + completed_text = before_text[:cursor_pos - prefix_len] + text + after_text + return prefix_len, completed_text + def completion_selected(self, text): prefix_len, ctext = self.get_completed_text(text)