Compare commits

..

No commits in common. "cd01d2f8c330c7ce850e6d52a9e8bc8601a20c96" and "93c859a3c4076709fc94cc19c91c87d796a555e2" have entirely different histories.

6 changed files with 15 additions and 67 deletions

View File

@ -2451,7 +2451,6 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
INFOPLIST_FILE = TuskerUITests/Info.plist; INFOPLIST_FILE = TuskerUITests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
LD_RUNPATH_SEARCH_PATHS = ( LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
@ -2805,7 +2804,6 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
INFOPLIST_FILE = TuskerUITests/Info.plist; INFOPLIST_FILE = TuskerUITests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
LD_RUNPATH_SEARCH_PATHS = ( LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
@ -2825,7 +2823,6 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
INFOPLIST_FILE = TuskerUITests/Info.plist; INFOPLIST_FILE = TuskerUITests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
LD_RUNPATH_SEARCH_PATHS = ( LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
@ -2959,8 +2956,8 @@
isa = XCRemoteSwiftPackageReference; isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://git.shadowfacts.net/shadowfacts/HTMLStreamer.git"; repositoryURL = "https://git.shadowfacts.net/shadowfacts/HTMLStreamer.git";
requirement = { requirement = {
kind = upToNextMinorVersion; branch = main;
minimumVersion = 0.1.0; kind = branch;
}; };
}; };
D63CC700290EC0B8000E19DE /* XCRemoteSwiftPackageReference "sentry-cocoa" */ = { D63CC700290EC0B8000E19DE /* XCRemoteSwiftPackageReference "sentry-cocoa" */ = {

View File

@ -30,31 +30,20 @@ extension NSAttributedString {
extension NSMutableAttributedString { extension NSMutableAttributedString {
func trimLeadingCharactersInSet(_ charSet: CharacterSet) { func trimLeadingCharactersInSet(_ charSet: CharacterSet) {
var end = string.startIndex var range = (string as NSString).rangeOfCharacter(from: charSet)
while end < string.endIndex && charSet.contains(string.unicodeScalars[end]) {
end = string.unicodeScalars.index(after: end) while range.length != 0 && range.location == 0 {
} replaceCharacters(in: range, with: "")
if end > string.startIndex { range = (string as NSString).rangeOfCharacter(from: charSet)
let length = string.utf16.distance(from: string.startIndex, to: end)
replaceCharacters(in: NSRange(location: 0, length: length), with: "")
} }
} }
func trimTrailingCharactersInSet(_ charSet: CharacterSet) { func trimTrailingCharactersInSet(_ charSet: CharacterSet) {
if string.isEmpty { var range = (string as NSString).rangeOfCharacter(from: charSet, options: .backwards)
return
} while range.length != 0 && range.length + range.location == length {
var start = string.index(before: string.endIndex) replaceCharacters(in: range, with: "")
while start > string.startIndex && charSet.contains(string.unicodeScalars[start]) { range = (string as NSString).rangeOfCharacter(from: charSet, options: .backwards)
start = string.unicodeScalars.index(before: start)
}
if start < string.endIndex {
if start != string.startIndex || !charSet.contains(string.unicodeScalars[start]) {
start = string.unicodeScalars.index(after: start)
}
let location = string.utf16.distance(from: string.startIndex, to: start)
let length = string.utf16.distance(from: start, to: string.endIndex)
replaceCharacters(in: NSRange(location: location, length: length), with: "")
} }
} }

View File

@ -60,7 +60,7 @@ extension HTMLConverter {
if clazz == "invisible" { if clazz == "invisible" {
return .skip return .skip
} else if clazz == "ellipsis" { } else if clazz == "ellipsis" {
return .append("") return .replace("")
} else { } else {
return .default return .default
} }

View File

@ -388,11 +388,7 @@ class ConversationMainStatusCollectionViewCell: UICollectionViewListCell, Status
let html = translation?.content ?? status.content let html = translation?.content ?? status.content
let attributedContent = ConversationMainStatusCollectionViewCell.htmlConverter.convert(html) let attributedContent = ConversationMainStatusCollectionViewCell.htmlConverter.convert(html)
let collapsedContent = NSMutableAttributedString(attributedString: attributedContent) doUpdateUI(status: status, content: attributedContent)
collapsedContent.collapseWhitespace()
collapsedContent.trimLeadingCharactersInSet(.whitespacesAndNewlines)
collapsedContent.trimTrailingCharactersInSet(.whitespacesAndNewlines)
doUpdateUI(status: status, content: collapsedContent)
if !status.spoilerText.isEmpty, if !status.spoilerText.isEmpty,
let translated = translation?.spoilerText { let translated = translation?.spoilerText {

View File

@ -616,11 +616,7 @@ class TimelineStatusCollectionViewCell: UICollectionViewListCell, StatusCollecti
} }
let content = precomputedContent ?? TimelineStatusCollectionViewCell.htmlConverter.convert(status.content) let content = precomputedContent ?? TimelineStatusCollectionViewCell.htmlConverter.convert(status.content)
let collapsedContent = NSMutableAttributedString(attributedString: content) doUpdateUI(status: status, content: content)
collapsedContent.collapseWhitespace()
collapsedContent.trimLeadingCharactersInSet(.whitespacesAndNewlines)
collapsedContent.trimTrailingCharactersInSet(.whitespacesAndNewlines)
doUpdateUI(status: status, content: collapsedContent)
doUpdateTimestamp(status: status) doUpdateTimestamp(status: status)
timestampLabel.isHidden = showPinned timestampLabel.isHidden = showPinned

View File

@ -17,36 +17,6 @@ class AttributedStringHelperTests: XCTestCase {
override func tearDown() { override func tearDown() {
} }
func testTrimLeading() {
let a = NSMutableAttributedString(string: " a ")
a.trimLeadingCharactersInSet(.whitespaces)
XCTAssertEqual(a, NSAttributedString(string: "a "))
let b = NSMutableAttributedString(string: " ")
b.trimLeadingCharactersInSet(.whitespaces)
XCTAssertEqual(b, NSAttributedString(string: ""))
let c = NSMutableAttributedString(string: "")
c.trimLeadingCharactersInSet(.whitespaces)
XCTAssertEqual(c, NSAttributedString(string: ""))
let d = NSMutableAttributedString(string: "abc")
d.trimLeadingCharactersInSet(.whitespaces)
XCTAssertEqual(d, NSAttributedString(string: "abc"))
}
func testTrimTrailing() {
let a = NSMutableAttributedString(string: " a ")
a.trimTrailingCharactersInSet(.whitespaces)
XCTAssertEqual(a, NSAttributedString(string: " a"))
let b = NSMutableAttributedString(string: " ")
b.trimTrailingCharactersInSet(.whitespaces)
XCTAssertEqual(b, NSAttributedString(string: ""))
let c = NSMutableAttributedString(string: "")
c.trimTrailingCharactersInSet(.whitespaces)
XCTAssertEqual(c, NSAttributedString(string: ""))
let d = NSMutableAttributedString(string: "abc")
d.trimTrailingCharactersInSet(.whitespaces)
XCTAssertEqual(d, NSAttributedString(string: "abc"))
}
func testCollapsingWhitespace() { func testCollapsingWhitespace() {
var str = NSAttributedString(string: "test 1\n") var str = NSAttributedString(string: "test 1\n")
XCTAssertEqual(str.collapsingWhitespace(), NSAttributedString(string: "test 1\n")) XCTAssertEqual(str.collapsingWhitespace(), NSAttributedString(string: "test 1\n"))