From fbb5208aac6c32869ac3951f537447149b94fe5b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 2 Jan 2022 08:46:18 +0530 Subject: [PATCH] Completion popup: Fix display of items containing line breaks --- src/calibre/gui2/complete2.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/complete2.py b/src/calibre/gui2/complete2.py index e46f756db2..581cdbe9ea 100644 --- a/src/calibre/gui2/complete2.py +++ b/src/calibre/gui2/complete2.py @@ -63,6 +63,11 @@ class CompleteModel(QAbstractListModel): # {{{ def data(self, index, role): if role == Qt.ItemDataRole.DisplayRole: + try: + return self.current_items[index.row()].replace('\n', ' ') + except IndexError: + pass + if role == Qt.ItemDataRole.UserRole: try: return self.current_items[index.row()] except IndexError: @@ -106,7 +111,7 @@ class Completer(QListView): # {{{ if not self.isVisible(): return self.hide() - text = self.model().data(index, Qt.ItemDataRole.DisplayRole) + text = self.model().data(index, Qt.ItemDataRole.UserRole) self.item_selected.emit(str(text)) def set_items(self, items): @@ -531,7 +536,7 @@ if __name__ == '__main__': d.setLayout(QVBoxLayout()) le = EditWithComplete(d) d.layout().addWidget(le) - items = ['one', 'otwo', 'othree', 'ooone', 'ootwo', 'other', 'odd', 'over', 'orc', 'oven', 'owe', + items = ['oane\n line2\n line3', 'otwo', 'othree', 'ooone', 'ootwo', 'other', 'odd', 'over', 'orc', 'oven', 'owe', 'oothree', 'a1', 'a2','Edgas', 'Èdgar', 'Édgaq', 'Edgar', 'Édgar'] le.update_items_cache(items) le.show_initial_value('')