Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.
Merged
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
10 changes: 6 additions & 4 deletions Classes/Repository/RepositoryCodeBlobViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ final class RepositoryCodeBlobViewController: UIViewController, EmptyViewDelegat
branch: branch,
path: path.path
) { [weak self] (result) in
self?.feedRefresh.endRefreshing()
switch result {
case .success(let text):
self?.handle(text: text)
Expand All @@ -162,17 +161,20 @@ final class RepositoryCodeBlobViewController: UIViewController, EmptyViewDelegat
}
}

func error(cannotLoad: Bool) {
private func error(cannotLoad: Bool) {
feedRefresh.endRefreshing()
emptyView.isHidden = false
emptyView.label.text = cannotLoad
? NSLocalizedString("Cannot display file as text", comment: "")
: NSLocalizedString("Error loading file", comment: "")
}

func handle(text: String) {
private func handle(text: String) {
emptyView.isHidden = true
didFetchPayload(text)
codeView.set(code: text)
codeView.set(code: text) { [weak self] in
self?.feedRefresh.endRefreshing()
}
}

// MARK: EmptyViewDelegate
Expand Down
8 changes: 6 additions & 2 deletions Classes/Views/CodeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class CodeView: UITextView {
}

// MARK: Public API
func set(code: String, language: String? = nil) {
func set(code: String, language: String? = nil, completion: @escaping () -> Void) {
DispatchQueue.global().async {
let maybeHighlighted: NSAttributedString?
if let language = language {
Expand All @@ -40,9 +40,13 @@ final class CodeView: UITextView {
// Automatic language detection
maybeHighlighted = GithubHighlighting.highlight(code)
}
guard let highlighted = maybeHighlighted else { return }
guard let highlighted = maybeHighlighted else {
DispatchQueue.main.async(execute: completion)
return
}
DispatchQueue.main.async { [weak self] in
self?.set(attributedCode: highlighted)
completion()
}
}
}
Expand Down