Skip to content
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
8 changes: 2 additions & 6 deletions CodeEdit/Features/Documents/CodeFileDocument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,9 @@ final class CodeFileDocument: NSDocument, ObservableObject {
/// Document-specific overridden line wrap preference.
@Published var wrapLines: Bool?

/// The type of data this document contains.
/// The type of data this file document contains.
///
/// If for example, the file ends with `.py`, its type is a text file.
/// Or if it ends with `.png`, then it is an image.
/// Same goes for PDF and video formats.
///
/// Also, if the text content is not empty, it is a text file.
/// If its text content is not nil, a `text` UTType is returned.
///
/// - Note: The UTType doesn't necessarily mean the file extension, it can be the MIME
/// type or any other form of data representation.
Expand Down
21 changes: 10 additions & 11 deletions CodeEdit/Features/Editor/Views/NonTextFileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,16 @@ struct NonTextFileView: View {

Group {
if let fileURL = fileDocument.fileURL {

switch fileDocument.utType {
case .some(.image):
ImageFileView(fileURL)
.modifier(UpdateStatusBarInfo(withURL: fileURL))

case .some(.pdf):
PDFFileView(fileURL)
.modifier(UpdateStatusBarInfo(withURL: fileURL))

default:
if let utType = fileDocument.utType {

if utType.conforms(to: .image) {
ImageFileView(fileURL)
.modifier(UpdateStatusBarInfo(withURL: fileURL))
} else if utType.conforms(to: .pdf) {
PDFFileView(fileURL)
.modifier(UpdateStatusBarInfo(withURL: fileURL))
}
} else {
AnyFileView(fileURL)
.modifier(UpdateStatusBarInfo(withURL: fileURL))
}
Expand Down