Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 79f4ac9

Browse files
authored
Code blocks share system font adjustment, use StyledText (#1752)
1 parent e01b57a commit 79f4ac9

File tree

5 files changed

+23
-17
lines changed

5 files changed

+23
-17
lines changed

Classes/Issues/Comments/CodeBlock/IssueCommentCodeBlockCell.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import UIKit
1010
import IGListKit
11+
import StyledText
1112

1213
final class IssueCommentCodeBlockCell: IssueCommentBaseCell, ListBindable {
1314

@@ -24,7 +25,7 @@ final class IssueCommentCodeBlockCell: IssueCommentBaseCell, ListBindable {
2425
right: Styles.Sizes.commentGutter
2526
)
2627

27-
let textView = AttributedStringView()
28+
let textView = StyledTextView()
2829
let scrollView = UIScrollView()
2930

3031
override init(frame: CGRect) {
@@ -67,7 +68,7 @@ final class IssueCommentCodeBlockCell: IssueCommentBaseCell, ListBindable {
6768
let contentSize = viewModel.contentSize
6869
scrollView.contentSize = contentSize
6970

70-
textView.configureAndSizeToFit(text: viewModel.code, width: 0)
71+
textView.configure(renderer: viewModel.code, width: 0)
7172
}
7273

7374
}

Classes/Issues/Comments/CodeBlock/IssueCommentCodeBlockModel.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88

99
import Foundation
1010
import IGListKit
11+
import StyledText
1112

1213
final class IssueCommentCodeBlockModel: NSObject, ListDiffable {
1314

14-
let code: NSAttributedStringSizing
15+
let code: StyledTextRenderer
1516
let language: String?
1617

1718
init(
18-
code: NSAttributedStringSizing,
19+
code: StyledTextRenderer,
1920
language: String?
2021
) {
2122
self.code = code
@@ -25,7 +26,7 @@ final class IssueCommentCodeBlockModel: NSObject, ListDiffable {
2526
// MARK: Public API
2627

2728
var contentSize: CGSize {
28-
return code.textViewSize(0)
29+
return code.viewSize(width: 0)
2930
}
3031

3132
// MARK: ListDiffable

Classes/Issues/Comments/Markdown/CMarkParsing.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ private extension Element {
278278
case .hr:
279279
return IssueCommentHrModel()
280280
case .codeBlock(let text, let language):
281-
return CodeBlockElement(text: text, language: language)
281+
return CodeBlockElement(text: text, language: language, contentSizeCategory: options.contentSizeCategory)
282282
case .heading(let text, let level):
283283
let builder = StyledTextBuilder.markdownBase()
284284
let style: TextStyle

Classes/Issues/Comments/Markdown/CodeBlockModel.swift

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@
77
//
88

99
import Foundation
10+
import StyledText
1011

11-
func CodeBlockElement(text: String, language: String?) -> IssueCommentCodeBlockModel {
12+
func CodeBlockElement(
13+
text: String,
14+
language: String?,
15+
contentSizeCategory: UIContentSizeCategory
16+
) -> IssueCommentCodeBlockModel {
1217
let trimmedText = text.trimmingCharacters(in: .whitespacesAndNewlines)
1318
let attributedString: NSAttributedString
1419

@@ -30,18 +35,17 @@ func CodeBlockElement(text: String, language: String?) -> IssueCommentCodeBlockM
3035
inset.left += IssueCommentCodeBlockCell.scrollViewInset.left
3136
inset.right += IssueCommentCodeBlockCell.scrollViewInset.right
3237

33-
// TODO use builder later
34-
// let builder = StyledTextBuilder.markdownBase()
35-
// .add(attributedText: highlighted)
36-
37-
let stringSizing = NSAttributedStringSizing(
38-
containerWidth: 0,
39-
attributedText: attributedString,
38+
let backgroundColor = Styles.Colors.Gray.lighter.color
39+
let builder = StyledTextBuilder(attributedText: attributedString)
40+
.add(attributes: [.backgroundColor: backgroundColor])
41+
let string = StyledTextRenderer(
42+
string: builder.build(),
43+
contentSizeCategory: contentSizeCategory,
4044
inset: inset,
41-
backgroundColor: Styles.Colors.Gray.lighter.color
45+
backgroundColor: backgroundColor
4246
)
4347
return IssueCommentCodeBlockModel(
44-
code: stringSizing,
48+
code: string,
4549
language: fixedLanguage
4650
)
4751
}

Classes/Systems/GithubHighlighting.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ enum GithubHighlighting {
1313

1414
private static var shared: Highlightr? = {
1515
let h = Highlightr()
16-
h?.setTheme(to: "github", fontSize: Styles.Text.code.size)
16+
h?.setTheme(to: "github", fontSize: Styles.Text.code.preferredFont.pointSize)
1717
return h
1818
}()
1919

0 commit comments

Comments
 (0)