Skip to content

Commit d51c9d2

Browse files
authored
View text files that are not UTF-8 encoded (#1727)
view text files that are not UTF-8 encoded
1 parent 2f94292 commit d51c9d2

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

CodeEdit/Features/Documents/CodeFileDocument.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,9 @@ final class CodeFileDocument: NSDocument, ObservableObject {
124124
/// This function is used for decoding files.
125125
/// It should not throw error as unsupported files can still be opened by QLPreviewView.
126126
override func read(from data: Data, ofType _: String) throws {
127-
guard let content = String(data: data, encoding: .utf8) else { return }
128-
self.content = content
127+
var nsString: NSString?
128+
NSString.stringEncoding(for: data, encodingOptions: nil, convertedString: &nsString, usedLossyConversion: nil)
129+
self.content = nsString as? String ?? ""
129130
}
130131

131132
/// Triggered when change occurred

0 commit comments

Comments
 (0)