mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-10-31 16:24:11 +00:00
fix: completion service matches now any character
also added a test for it
This commit is contained in:
+5
-4
@@ -9,7 +9,8 @@ import Combine
|
||||
import Foundation
|
||||
|
||||
private enum SuggestionTriggerRegex {
|
||||
static let atOrHash = /[@#]\w*/
|
||||
/// Matches any string of characters after an @ or # that is not a whitespace
|
||||
static let atOrHash = /[@#]\S*/
|
||||
|
||||
static let at: Character = "@"
|
||||
static let hash: Character = "#"
|
||||
@@ -138,11 +139,11 @@ final class CompletionSuggestionService: CompletionSuggestionServiceProtocol {
|
||||
guard !searchText.isEmpty else {
|
||||
return true
|
||||
}
|
||||
let containedInUserID = userID.localizedStandardContains(searchText.lowercased())
|
||||
let containedInUserID = userID.localizedStandardContains(searchText)
|
||||
|
||||
let containedInDisplayName: Bool
|
||||
if let displayName {
|
||||
containedInDisplayName = displayName.localizedStandardContains(searchText.lowercased())
|
||||
containedInDisplayName = displayName.localizedStandardContains(searchText)
|
||||
} else {
|
||||
containedInDisplayName = false
|
||||
}
|
||||
@@ -155,6 +156,6 @@ final class CompletionSuggestionService: CompletionSuggestionServiceProtocol {
|
||||
guard !searchText.isEmpty else {
|
||||
return true
|
||||
}
|
||||
return roomName.localizedStandardContains(searchText.lowercased()) || roomAlias.localizedStandardContains(searchText.lowercased())
|
||||
return roomName.localizedStandardContains(searchText) || roomAlias.localizedStandardContains(searchText)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -372,4 +372,33 @@ final class CompletionSuggestionServiceTests: XCTestCase {
|
||||
service.processTextMessage("#pr test @al", selectedRange: .init(location: 9, length: 1))
|
||||
try await deffered.fulfill()
|
||||
}
|
||||
|
||||
func testSuggestionsContainingNonAlphanumericCharacters() async throws {
|
||||
let alice: RoomMemberProxyMock = .mockAlice
|
||||
// We keep the users in the tests since they should not appear in the suggestions when using the room trigger
|
||||
let members: [RoomMemberProxyMock] = [alice, .mockBob, .mockCharlie, .mockMe]
|
||||
let roomProxyMock = JoinedRoomProxyMock(.init(id: "roomID", name: "test", members: members))
|
||||
let roomSummaryProvider = RoomSummaryProviderMock(.init(state: .loaded(.mockRooms)))
|
||||
let service = CompletionSuggestionService(roomProxy: roomProxyMock,
|
||||
roomListPublisher: roomSummaryProvider.roomListPublisher.eraseToAnyPublisher())
|
||||
|
||||
var deferred = deferFulfillment(service.suggestionsPublisher) { suggestions in
|
||||
suggestions == []
|
||||
}
|
||||
|
||||
try await deferred.fulfill()
|
||||
|
||||
deferred = deferFulfillment(service.suggestionsPublisher) { suggestions in
|
||||
suggestions == [.init(suggestionType: .room(.init(id: "6",
|
||||
canonicalAlias: "#prelude-foundation:matrix.org",
|
||||
name: "Prelude to Foundation",
|
||||
avatar: .room(id: "6",
|
||||
name: "Prelude to Foundation",
|
||||
avatarURL: nil))),
|
||||
range: .init(),
|
||||
rawSuggestionText: "#prelude-")]
|
||||
}
|
||||
service.setSuggestionTrigger(.init(type: .room, text: "#prelude-", range: .init()))
|
||||
try await deferred.fulfill()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user