From d8dc88449834210a7107735818069bbd797eb750 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 19 Nov 2018 19:42:40 +0530 Subject: [PATCH] Edit book: Fix suggestions in completion popup not being sorted. Fixes #1803985 [[enhancement] editor, make auto fill a href more "natural" order](https://bugs.launchpad.net/calibre/+bug/1803985) --- src/calibre/gui2/tweak_book/completion/basic.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/tweak_book/completion/basic.py b/src/calibre/gui2/tweak_book/completion/basic.py index 56ead0af4c..145813fd8b 100644 --- a/src/calibre/gui2/tweak_book/completion/basic.py +++ b/src/calibre/gui2/tweak_book/completion/basic.py @@ -20,6 +20,7 @@ from calibre.gui2.tweak_book import current_container, editors from calibre.gui2.tweak_book.completion.utils import control, data, DataError from calibre.utils.ipc import eintr_retry_call from calibre.utils.matcher import Matcher +from calibre.utils.icu import numeric_sort_key Request = namedtuple('Request', 'id type data query') @@ -123,6 +124,7 @@ def complete_anchor(name, data_conn): if isinstance(data, tuple) and len(data) > 1 and isinstance(data[1], dict): return frozenset(data[1]), data[1], {} + _current_matcher = (None, None, None) @@ -133,7 +135,7 @@ def handle_control_request(request, data_conn): items, descriptions, matcher_kwargs = ans fingerprint = hash(items) if fingerprint != _current_matcher[0] or matcher_kwargs != _current_matcher[1]: - _current_matcher = (fingerprint, matcher_kwargs, Matcher(items, **matcher_kwargs)) + _current_matcher = (fingerprint, matcher_kwargs, Matcher(sorted(items, key=numeric_sort_key), **matcher_kwargs)) if request.query: items = _current_matcher[-1](request.query, limit=50) else: @@ -177,6 +179,8 @@ class HandleDataRequest(QObject): return self.result, self.tb finally: del self.result, self.tb + + handle_data_request = HandleDataRequest() control_funcs = {name:func for name, func in globals().iteritems() if getattr(func, 'function_type', None) == 'control'}