Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions NextcloudTalk/Chat/Chat views/MessageBodyTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ - (instancetype)init
return self;
}

- (CGSize)intrinsicContentSize {
CGSize superSize = [super intrinsicContentSize];

// When a paragraphStyle with firstLineHeadIndent/headIndent is used, the
// intrinsicContentSize might not be accurate and the last word/character is wrapped,
// due to the size being too small. In that case usedRectForTextContainer reports
// a non-zero x value, we add to the width of the intrinsicContentSize
if (superSize.width < UINT16_MAX) {
CGRect usedRect = [self.layoutManager usedRectForTextContainer:self.textContainer];

if (usedRect.origin.x > 0) {
return CGSizeMake(superSize.width + usedRect.origin.x, superSize.height);
}
}

return superSize;
}

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
return NO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,4 @@ final class UnitBaseChatViewControllerTest: TestBaseRealm {
XCTAssertEqual(baseController.getCellHeight(for: testMessage, with: 300), 171.0)
}

/*
func testCellWithMarkdownQuoteHeight() throws {
// Normal chat message
testMessage.message = "> 1234567890123456789012345678901"
XCTAssertEqual(baseController.getCellHeight(for: testMessage, with: 372), 96.0)
}
*/

}
25 changes: 25 additions & 0 deletions NextcloudTalkTests/Unit/Chat/UnitMessageBodyTextViewTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
// SPDX-License-Identifier: GPL-3.0-or-later
//

import XCTest
@testable import NextcloudTalk

final class UnitMessageBodyTextViewTest: TestBaseRealm {

func testCellWithMarkdownQuoteHeight() throws {
let activeAccount = NCDatabaseManager.sharedInstance().activeAccount()
let testMessage = NCChatMessage(dictionary: [:], andAccountId: activeAccount.accountId)!

// Markdown message
testMessage.message = "> 1234567890123456789012345678"
testMessage.isMarkdownMessage = true

let messageTextView = MessageBodyTextView()
messageTextView.attributedText = testMessage.parsedMarkdownForChat()

XCTAssertEqual(messageTextView.intrinsicContentSize, CGSize(width: 259, height: 20))
}

}
Loading