mirror of
https://github.com/coteditor/CotEditor.git
synced 2024-09-11 11:25:57 +03:00
Evaluate shebang on first saving (close #668)
This commit is contained in:
parent
38676e7a8c
commit
21c8a19384
@ -14,6 +14,7 @@ develop
|
||||
|
||||
- Optimize script menu updating performance.
|
||||
- Change behavior to avoid showing incompatible char list on undoing encoding change.
|
||||
- Evaluate also the shebang to specify the syntax style on saving the document newly.
|
||||
- Scale up character view in character inspector.
|
||||
- Change drawing font for some invisible characters to draw them at a better position.
|
||||
- Update “JavaScript” syntax style.
|
||||
|
@ -418,34 +418,37 @@ final class Document: NSDocument, AdditionalDocumentPreparing, EncodingHolder {
|
||||
}
|
||||
|
||||
guard error == nil else { return }
|
||||
guard let strongSelf = self else { return }
|
||||
|
||||
assert(Thread.isMainThread)
|
||||
|
||||
// apply syntax style that is inferred from the file name
|
||||
// apply syntax style that is inferred from the file name or the shebang
|
||||
if saveOperation == .saveAsOperation {
|
||||
let fileName = url.lastPathComponent
|
||||
if let styleName = SyntaxManager.shared.styleName(documentFileName: fileName) {
|
||||
self?.setSyntaxStyle(name: styleName)
|
||||
if let styleName = SyntaxManager.shared.styleName(documentFileName: fileName)
|
||||
?? SyntaxManager.shared.styleName(documentContent: strongSelf.string)
|
||||
// -> Due to the async-saving, self.string can be changed from the actual saved contents.
|
||||
// But we don't care about that.
|
||||
{
|
||||
strongSelf.setSyntaxStyle(name: styleName)
|
||||
}
|
||||
}
|
||||
|
||||
if saveOperation != .autosaveElsewhereOperation {
|
||||
// update file information
|
||||
self?.analyzer.invalidateFileInfo()
|
||||
strongSelf.analyzer.invalidateFileInfo()
|
||||
|
||||
// send file update notification for the external editor protocol (ODB Editor Suite)
|
||||
let odbEventType: ODBEventSender.EventType = (saveOperation == .saveAsOperation) ? .newLocation : .modified
|
||||
self?.odbEventSender?.sendEvent(type: odbEventType, fileURL: url)
|
||||
strongSelf.odbEventSender?.sendEvent(type: odbEventType, fileURL: url)
|
||||
}
|
||||
|
||||
if let strongSelf = self {
|
||||
switch saveOperation {
|
||||
case .saveOperation,
|
||||
.saveAsOperation,
|
||||
.saveToOperation:
|
||||
ScriptManager.shared.dispatchEvent(documentSaved: strongSelf)
|
||||
default: break
|
||||
}
|
||||
switch saveOperation {
|
||||
case .saveOperation,
|
||||
.saveAsOperation,
|
||||
.saveToOperation:
|
||||
ScriptManager.shared.dispatchEvent(documentSaved: strongSelf)
|
||||
default: break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user