Fix lossy option in convert command by scripting

This commit is contained in:
1024jp 2016-12-27 17:39:51 +09:00
parent 8a3a9d7cea
commit 3f38e728c2
3 changed files with 8 additions and 4 deletions

View File

@ -18,6 +18,7 @@ develop
- Fix an issue where the application could crash after lossy encoding change if line endings are CR/LF.
- Fix an issue where incompatible charaters highlight could highlight wrong characters if line endings are CR/LF.
- Fix an issue where the zoomed characer in the characer inspector was flipped when the popover is detached.
- Fix an issue where `lossy` option in `convert` command by AppleScript scripting was ignored.
- Fix an issue on the AppleScript scripting where `range` property of `document` contents could be wrong if document line endings are not LF. (thanks to Kaito Udagawa!).

View File

@ -210,7 +210,7 @@ extension Document {
return .yes
}
let lossy = (arguments?["Lossy"] as? Bool) ?? false
let lossy = (arguments?["lossy"] as? Bool) ?? false
return self.changeEncoding(to: encoding, withUTF8BOM: false, askLossy: false, lossy: lossy) ? .yes : .no
}

View File

@ -867,12 +867,15 @@ final class Document: NSDocument, AdditionalDocumentPreparing, EncodingHolder {
let encodingName = String.localizedName(of: encoding, withUTF8BOM: withUTF8BOM)
// ask lossy
if askLossy {
guard self.string.canBeConverted(to: encoding) else {
// check if conversion is lossy
if !self.string.canBeConverted(to: encoding) {
if askLossy {
let error = EncodingError(kind: .lossyEncodingConversion, encoding: encoding, withUTF8BOM: withUTF8BOM, attempter: self)
self.presentErrorAsSheet(error)
return false
} else if !lossy {
return false
}
}