From deac31e48dc4f130e0381885b01988901bb699ee Mon Sep 17 00:00:00 2001 From: Mauro Romito Date: Mon, 11 May 2026 16:58:25 +0200 Subject: [PATCH] remove code related to the previous bidi usage implementation of whitespaces for the timestamp label --- .../Other/Extensions/LayoutDirection.swift | 22 ------ .../Sources/Other/Extensions/String.swift | 16 ----- NSE/SupportingFiles/target.yml | 1 - UnitTests/Sources/StringTests.swift | 23 ------ .../Sources/TextBasedRoomTimelineTests.swift | 70 ------------------- 5 files changed, 132 deletions(-) delete mode 100644 ElementX/Sources/Other/Extensions/LayoutDirection.swift delete mode 100644 UnitTests/Sources/TextBasedRoomTimelineTests.swift diff --git a/ElementX/Sources/Other/Extensions/LayoutDirection.swift b/ElementX/Sources/Other/Extensions/LayoutDirection.swift deleted file mode 100644 index b414ed4ae..000000000 --- a/ElementX/Sources/Other/Extensions/LayoutDirection.swift +++ /dev/null @@ -1,22 +0,0 @@ -// -// Copyright 2025 Element Creations Ltd. -// Copyright 2023-2025 New Vector Ltd. -// -// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial. -// Please see LICENSE files in the repository root for full details. -// - -import SwiftUI - -extension LayoutDirection { - var isolateLayoutUnicodeString: String { - switch self { - case .leftToRight: - return "\u{2066}" - case .rightToLeft: - return "\u{2067}" - default: - return "" - } - } -} diff --git a/ElementX/Sources/Other/Extensions/String.swift b/ElementX/Sources/Other/Extensions/String.swift index 47a700d5d..7b4a4dec2 100644 --- a/ElementX/Sources/Other/Extensions/String.swift +++ b/ElementX/Sources/Other/Extensions/String.swift @@ -41,22 +41,6 @@ extension String { } } -extension String { - static func generateBreakableWhitespaceEnd(whitespaceCount: Int, layoutDirection: LayoutDirection) -> String { - guard whitespaceCount > 0 else { - return "" - } - - var whiteSpaces = layoutDirection.isolateLayoutUnicodeString - - // fixed size whitespace of size 1/3 em per character - whiteSpaces += String(repeating: "\u{2004}", count: whitespaceCount) - - // braille whitespace, which is non breakable but makes previous whitespaces breakable - return whiteSpaces + "\u{2800}" - } -} - extension String { func ellipsize(length: Int) -> String { guard count > length else { diff --git a/NSE/SupportingFiles/target.yml b/NSE/SupportingFiles/target.yml index 03ba2cf55..307613c4c 100644 --- a/NSE/SupportingFiles/target.yml +++ b/NSE/SupportingFiles/target.yml @@ -99,7 +99,6 @@ targets: - path: ../../ElementX/Sources/Other/Extensions/Dictionary.swift - path: ../../ElementX/Sources/Other/Extensions/FileManager.swift - path: ../../ElementX/Sources/Other/Extensions/ImageCache.swift - - path: ../../ElementX/Sources/Other/Extensions/LayoutDirection.swift - path: ../../ElementX/Sources/Other/Extensions/NSRegularExpresion.swift - path: ../../ElementX/Sources/Other/Extensions/ProcessInfo.swift - path: ../../ElementX/Sources/Other/Extensions/String.swift diff --git a/UnitTests/Sources/StringTests.swift b/UnitTests/Sources/StringTests.swift index 3f8e630e7..9e5008457 100644 --- a/UnitTests/Sources/StringTests.swift +++ b/UnitTests/Sources/StringTests.swift @@ -55,29 +55,6 @@ struct StringTests { #expect("1️⃣2️⃣3️⃣".asciified() == "123", "The emoji should be converted to ASCII.") } - @Test - func generateBreakableWhitespaceEnd() { - var count = 5 - var result = "\u{2066}" + String(repeating: "\u{2004}", count: count) + "\u{2800}" - #expect(String.generateBreakableWhitespaceEnd(whitespaceCount: count, layoutDirection: .leftToRight) == result) - - count = 3 - result = "\u{2066}" + String(repeating: "\u{2004}", count: count) + "\u{2800}" - #expect(String.generateBreakableWhitespaceEnd(whitespaceCount: count, layoutDirection: .leftToRight) == result) - - count = 0 - result = "" - #expect(String.generateBreakableWhitespaceEnd(whitespaceCount: count, layoutDirection: .leftToRight) == result) - - count = 4 - result = "\u{2067}" + String(repeating: "\u{2004}", count: count) + "\u{2800}" - #expect(String.generateBreakableWhitespaceEnd(whitespaceCount: count, layoutDirection: .rightToLeft) == result) - - count = 0 - result = "" - #expect(String.generateBreakableWhitespaceEnd(whitespaceCount: count, layoutDirection: .rightToLeft) == result) - } - @Test func ellipsizeWorks() { #expect("ellipsize".ellipsize(length: 5) == "ellip…") diff --git a/UnitTests/Sources/TextBasedRoomTimelineTests.swift b/UnitTests/Sources/TextBasedRoomTimelineTests.swift deleted file mode 100644 index e1c3385da..000000000 --- a/UnitTests/Sources/TextBasedRoomTimelineTests.swift +++ /dev/null @@ -1,70 +0,0 @@ -// -// Copyright 2025 Element Creations Ltd. -// Copyright 2023-2025 New Vector Ltd. -// -// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial. -// Please see LICENSE files in the repository root for full details. -// - -@testable import ElementX -import Foundation -import Testing - -struct TextBasedRoomTimelineTests { - @Test - func textRoomTimelineItemWhitespaceEnd() { - let timestamp = Calendar.current.startOfDay(for: .now).addingTimeInterval(60 * 60) // 1:00 am - let timelineItem = TextRoomTimelineItem(id: .randomEvent, - timestamp: timestamp, - isOutgoing: true, - isEditable: true, - canBeRepliedTo: true, - sender: .init(id: UUID().uuidString), - content: .init(body: "Test")) - #expect(timelineItem.additionalWhitespaces() == timestamp.formattedTime().count + 1) - } - - @Test - func textRoomTimelineItemWhitespaceEndLonger() { - let timestamp = Calendar.current.startOfDay(for: .now).addingTimeInterval(-60) // 11:59 pm - let timelineItem = TextRoomTimelineItem(id: .randomEvent, - timestamp: timestamp, - isOutgoing: true, - isEditable: true, - canBeRepliedTo: true, - sender: .init(id: UUID().uuidString), - content: .init(body: "Test")) - #expect(timelineItem.additionalWhitespaces() == timestamp.formattedTime().count + 1) - } - - @Test - func textRoomTimelineItemWhitespaceEndWithEdit() { - let timestamp = Date.mock - var timelineItem = TextRoomTimelineItem(id: .randomEvent, - timestamp: timestamp, - isOutgoing: true, - isEditable: true, - canBeRepliedTo: true, - sender: .init(id: UUID().uuidString), - content: .init(body: "Test")) - timelineItem.properties.isEdited = true - let editedCount = L10n.commonEditedSuffix.count - #expect(timelineItem.additionalWhitespaces() == timestamp.formattedTime().count + editedCount + 2) - } - - @Test - func textRoomTimelineItemWhitespaceEndWithEditAndAlert() { - let timestamp = Date.mock - var timelineItem = TextRoomTimelineItem(id: .randomEvent, - timestamp: timestamp, - isOutgoing: true, - isEditable: true, - canBeRepliedTo: true, - sender: .init(id: UUID().uuidString), - content: .init(body: "Test")) - timelineItem.properties.isEdited = true - timelineItem.properties.deliveryStatus = .sendingFailed(.unknown) - let editedCount = L10n.commonEditedSuffix.count - #expect(timelineItem.additionalWhitespaces() == timestamp.formattedTime().count + editedCount + 5) - } -}