Skip to content

Commit

Permalink
View text files that are not UTF-8 encoded (#1727)
Browse files Browse the repository at this point in the history
view text files that are not UTF-8 encoded
plbstl authored May 21, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 2f94292 commit d51c9d2
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions CodeEdit/Features/Documents/CodeFileDocument.swift
Original file line number Diff line number Diff line change
@@ -124,8 +124,9 @@ final class CodeFileDocument: NSDocument, ObservableObject {
/// This function is used for decoding files.
/// It should not throw error as unsupported files can still be opened by QLPreviewView.
override func read(from data: Data, ofType _: String) throws {
guard let content = String(data: data, encoding: .utf8) else { return }
self.content = content
var nsString: NSString?
NSString.stringEncoding(for: data, encodingOptions: nil, convertedString: &nsString, usedLossyConversion: nil)
self.content = nsString as? String ?? ""
}

/// Triggered when change occurred

0 comments on commit d51c9d2

Please sign in to comment.