@@ -91,7 +91,8 @@ function isValidUTF8(bytes) {
91
91
92
92
export async function detectEncoding ( buffer ) {
93
93
if ( ! buffer || buffer . byteLength === 0 ) {
94
- return settings . value . defaultFileEncoding || "UTF-8" ;
94
+ const def = settings . value . defaultFileEncoding ;
95
+ return def === "auto" ? "UTF-8" : def || "UTF-8" ;
95
96
}
96
97
97
98
const bytes = new Uint8Array ( buffer ) ;
@@ -115,7 +116,9 @@ export async function detectEncoding(buffer) {
115
116
const encodings = [
116
117
...new Set ( [
117
118
"UTF-8" ,
118
- settings . value . defaultFileEncoding || "UTF-8" ,
119
+ settings . value . defaultFileEncoding === "auto"
120
+ ? "UTF-8"
121
+ : settings . value . defaultFileEncoding || "UTF-8" ,
119
122
"windows-1252" ,
120
123
"ISO-8859-1" ,
121
124
] ) ,
@@ -144,7 +147,8 @@ export async function detectEncoding(buffer) {
144
147
}
145
148
}
146
149
147
- return settings . value . defaultFileEncoding || "UTF-8" ;
150
+ const def = settings . value . defaultFileEncoding ;
151
+ return def === "auto" ? "UTF-8" : def || "UTF-8" ;
148
152
}
149
153
150
154
/**
@@ -165,6 +169,8 @@ export async function decode(buffer, charset) {
165
169
charset = settings . value . defaultFileEncoding ;
166
170
}
167
171
172
+ if ( charset === "auto" ) charset = "UTF-8" ;
173
+
168
174
charset = getEncoding ( charset ) . name ;
169
175
const text = await execDecode ( buffer , charset ) ;
170
176
@@ -186,6 +192,8 @@ export function encode(text, charset) {
186
192
charset = settings . value . defaultFileEncoding ;
187
193
}
188
194
195
+ if ( charset === "auto" ) charset = "UTF-8" ;
196
+
189
197
charset = getEncoding ( charset ) . name ;
190
198
return execEncode ( text , charset ) ;
191
199
}
0 commit comments