diff --git a/src/calibre/gui2/tweak_book/widgets.py b/src/calibre/gui2/tweak_book/widgets.py index 8a23acd078..27cff25653 100644 --- a/src/calibre/gui2/tweak_book/widgets.py +++ b/src/calibre/gui2/tweak_book/widgets.py @@ -733,9 +733,9 @@ class InsertLink(Dialog): frag = item.get('id', None) or item.get('name') if not frag: continue - text = lead_text(item, num_words=4) + text = lead_text(item, num_words=4).strip() ac.append((text, frag)) - ac.sort(key=lambda text_frag: numeric_sort_key(text_frag[0])) + ac.sort(key=lambda text_frag: numeric_sort_key(text_frag[0] or text_frag[1])) self.anchor_names.model().set_names(self.anchor_cache[name]) self.update_target()