mirror of
https://github.com/zhigang1992/GitHawk.git
synced 2026-04-30 21:11:45 +08:00
Code blocks share system font adjustment, use StyledText (#1752)
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
import UIKit
|
||||
import IGListKit
|
||||
import StyledText
|
||||
|
||||
final class IssueCommentCodeBlockCell: IssueCommentBaseCell, ListBindable {
|
||||
|
||||
@@ -24,7 +25,7 @@ final class IssueCommentCodeBlockCell: IssueCommentBaseCell, ListBindable {
|
||||
right: Styles.Sizes.commentGutter
|
||||
)
|
||||
|
||||
let textView = AttributedStringView()
|
||||
let textView = StyledTextView()
|
||||
let scrollView = UIScrollView()
|
||||
|
||||
override init(frame: CGRect) {
|
||||
@@ -67,7 +68,7 @@ final class IssueCommentCodeBlockCell: IssueCommentBaseCell, ListBindable {
|
||||
let contentSize = viewModel.contentSize
|
||||
scrollView.contentSize = contentSize
|
||||
|
||||
textView.configureAndSizeToFit(text: viewModel.code, width: 0)
|
||||
textView.configure(renderer: viewModel.code, width: 0)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,14 +8,15 @@
|
||||
|
||||
import Foundation
|
||||
import IGListKit
|
||||
import StyledText
|
||||
|
||||
final class IssueCommentCodeBlockModel: NSObject, ListDiffable {
|
||||
|
||||
let code: NSAttributedStringSizing
|
||||
let code: StyledTextRenderer
|
||||
let language: String?
|
||||
|
||||
init(
|
||||
code: NSAttributedStringSizing,
|
||||
code: StyledTextRenderer,
|
||||
language: String?
|
||||
) {
|
||||
self.code = code
|
||||
@@ -25,7 +26,7 @@ final class IssueCommentCodeBlockModel: NSObject, ListDiffable {
|
||||
// MARK: Public API
|
||||
|
||||
var contentSize: CGSize {
|
||||
return code.textViewSize(0)
|
||||
return code.viewSize(width: 0)
|
||||
}
|
||||
|
||||
// MARK: ListDiffable
|
||||
|
||||
@@ -278,7 +278,7 @@ private extension Element {
|
||||
case .hr:
|
||||
return IssueCommentHrModel()
|
||||
case .codeBlock(let text, let language):
|
||||
return CodeBlockElement(text: text, language: language)
|
||||
return CodeBlockElement(text: text, language: language, contentSizeCategory: options.contentSizeCategory)
|
||||
case .heading(let text, let level):
|
||||
let builder = StyledTextBuilder.markdownBase()
|
||||
let style: TextStyle
|
||||
|
||||
@@ -7,8 +7,13 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import StyledText
|
||||
|
||||
func CodeBlockElement(text: String, language: String?) -> IssueCommentCodeBlockModel {
|
||||
func CodeBlockElement(
|
||||
text: String,
|
||||
language: String?,
|
||||
contentSizeCategory: UIContentSizeCategory
|
||||
) -> IssueCommentCodeBlockModel {
|
||||
let trimmedText = text.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
let attributedString: NSAttributedString
|
||||
|
||||
@@ -30,18 +35,17 @@ func CodeBlockElement(text: String, language: String?) -> IssueCommentCodeBlockM
|
||||
inset.left += IssueCommentCodeBlockCell.scrollViewInset.left
|
||||
inset.right += IssueCommentCodeBlockCell.scrollViewInset.right
|
||||
|
||||
// TODO use builder later
|
||||
// let builder = StyledTextBuilder.markdownBase()
|
||||
// .add(attributedText: highlighted)
|
||||
|
||||
let stringSizing = NSAttributedStringSizing(
|
||||
containerWidth: 0,
|
||||
attributedText: attributedString,
|
||||
let backgroundColor = Styles.Colors.Gray.lighter.color
|
||||
let builder = StyledTextBuilder(attributedText: attributedString)
|
||||
.add(attributes: [.backgroundColor: backgroundColor])
|
||||
let string = StyledTextRenderer(
|
||||
string: builder.build(),
|
||||
contentSizeCategory: contentSizeCategory,
|
||||
inset: inset,
|
||||
backgroundColor: Styles.Colors.Gray.lighter.color
|
||||
backgroundColor: backgroundColor
|
||||
)
|
||||
return IssueCommentCodeBlockModel(
|
||||
code: stringSizing,
|
||||
code: string,
|
||||
language: fixedLanguage
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user