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)

This commit is contained in:
Kovid Goyal 2018-11-19 19:42:40 +05:30
parent 795d7f54ff
commit d8dc884498
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -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.gui2.tweak_book.completion.utils import control, data, DataError
from calibre.utils.ipc import eintr_retry_call from calibre.utils.ipc import eintr_retry_call
from calibre.utils.matcher import Matcher from calibre.utils.matcher import Matcher
from calibre.utils.icu import numeric_sort_key
Request = namedtuple('Request', 'id type data query') 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): if isinstance(data, tuple) and len(data) > 1 and isinstance(data[1], dict):
return frozenset(data[1]), data[1], {} return frozenset(data[1]), data[1], {}
_current_matcher = (None, None, None) _current_matcher = (None, None, None)
@ -133,7 +135,7 @@ def handle_control_request(request, data_conn):
items, descriptions, matcher_kwargs = ans items, descriptions, matcher_kwargs = ans
fingerprint = hash(items) fingerprint = hash(items)
if fingerprint != _current_matcher[0] or matcher_kwargs != _current_matcher[1]: 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: if request.query:
items = _current_matcher[-1](request.query, limit=50) items = _current_matcher[-1](request.query, limit=50)
else: else:
@ -177,6 +179,8 @@ class HandleDataRequest(QObject):
return self.result, self.tb return self.result, self.tb
finally: finally:
del self.result, self.tb del self.result, self.tb
handle_data_request = HandleDataRequest() handle_data_request = HandleDataRequest()
control_funcs = {name:func for name, func in globals().iteritems() if getattr(func, 'function_type', None) == 'control'} control_funcs = {name:func for name, func in globals().iteritems() if getattr(func, 'function_type', None) == 'control'}