Skip to content

Commit

Permalink
Fix UNIX script for DirectoryDocument (fix #1705)
Browse files Browse the repository at this point in the history
  • Loading branch information
1024jp committed Sep 12, 2024
1 parent 08c9abe commit 56b90a1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
- [beta] Add the Czech and Dutch localizations for strings newly added in CotEditor 5.0.0.


### Fixes

- [beta] Fix an issue that UNIX scripts could not get the document object displayed in a folder.


### Known Issues

- Strings newly added are not yet localized in French and Portuguese.
Expand Down
14 changes: 14 additions & 0 deletions CotEditor/Sources/DocumentController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,20 @@ final class DocumentController: NSDocumentController {

// MARK: Public Methods

/// The current `Document`.
var currentPlainTextDocument: Document? {

switch self.currentDocument {
case let document as Document:
document
case let document as DirectoryDocument:
document.currentDocument as? Document
default:
nil
}
}


/// Opens an untitled document with the given contents or recycles the transient document if available.
///
/// - Parameters:
Expand Down
2 changes: 1 addition & 1 deletion CotEditor/Sources/UnixScript.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ struct UnixScript: Script {
throw ScriptFileError(.read, url: self.url)
}

weak var document = await NSDocumentController.shared.currentDocument as? Document
weak var document = await (DocumentController.shared as! DocumentController).currentPlainTextDocument

let input: String?
if let inputType = InputType(scanning: script) {
Expand Down

0 comments on commit 56b90a1

Please sign in to comment.