From e7aac2a322da0f0ee3be3e3c69bb65338472f733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthieu=20D=C3=A9glon?= Date: Thu, 19 Dec 2024 10:46:47 +0100 Subject: [PATCH] refactor: Fix the shouldAddUserProposal --- Mail/Views/New Message/AutocompletionCell.swift | 4 +++- Mail/Views/New Message/AutocompletionView.swift | 12 +++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Mail/Views/New Message/AutocompletionCell.swift b/Mail/Views/New Message/AutocompletionCell.swift index 0d526d826..1dc65b223 100644 --- a/Mail/Views/New Message/AutocompletionCell.swift +++ b/Mail/Views/New Message/AutocompletionCell.swift @@ -80,9 +80,10 @@ struct AutocompletionCell: View { ) { self.addRecipient = { addRecipient($0 as! MergedContact) } self.autocompletion = autocompletion + self.highlight = highlight self.alreadyAppend = alreadyAppend self.unknownRecipient = unknownRecipient - title = autocompletion.name + title = autocompletion.email subtitle = autocompletion.email } @@ -97,6 +98,7 @@ struct AutocompletionCell: View { ) { self.addRecipient = { addRecipient($0 as! GroupContact) } self.autocompletion = autocompletion + self.highlight = highlight self.alreadyAppend = alreadyAppend self.unknownRecipient = unknownRecipient self.title = title diff --git a/Mail/Views/New Message/AutocompletionView.swift b/Mail/Views/New Message/AutocompletionView.swift index 161671946..f15b078bb 100644 --- a/Mail/Views/New Message/AutocompletionView.swift +++ b/Mail/Views/New Message/AutocompletionView.swift @@ -131,17 +131,19 @@ struct AutocompletionView: View { shouldAddUserProposal = !(realResults.count == 1 && realResults.first?.autocompletableName == textDebounce.text) - if shouldAddUserProposal { - combinedResults.append(MergedContact(email: textDebounce.text, local: nil, remote: nil)) - } - combinedResults.sort { lhs, rhs in guard let lhsContact = lhs as? MergedContact, let rhsContact = rhs as? MergedContact else { return false } return sortByRemoteAndName(lhs: lhsContact, rhs: rhsContact) } - let result = combinedResults.prefix(10) + var result = combinedResults.prefix(10) + + if shouldAddUserProposal { + let mergedContact = MergedContact(email: textDebounce.text, local: nil, remote: nil) + mergedContact.name = textDebounce.text + result.append(mergedContact) + } autocompletion = Array(result) }