mirror of
https://github.com/coteditor/CotEditor.git
synced 2024-09-11 11:25:57 +03:00
Perform auto whitespace trimming before explicit saving (close #1444)
This commit is contained in:
parent
0ed700f417
commit
250072c6e3
@ -20,6 +20,7 @@ Change Log
|
||||
- Update the character inspector to add labels for each item and display the Unicode version.
|
||||
- Deprecate the print font setting in the Print settings.
|
||||
- Deprecate the cursor type option.
|
||||
- Make sure to perform the automatic whitespace trimming every time before explicit saving by the user.
|
||||
- Migrate the sharing interface to the modern version.
|
||||
- [trivial] Migrate the Opacity toolbar item to popover in macOS 14.
|
||||
- [trivial] Disable the contextual menu for shortcut fields.
|
||||
|
@ -418,9 +418,17 @@ final class Document: NSDocument, AdditionalDocumentPreparing, EncodingHolder {
|
||||
|
||||
override func save(to url: URL, ofType typeName: String, for saveOperation: NSDocument.SaveOperationType, completionHandler: @escaping ((any Error)?) -> Void) {
|
||||
|
||||
assert(Thread.isMainThread)
|
||||
|
||||
// break undo grouping
|
||||
for layoutManager in self.textStorage.layoutManagers {
|
||||
layoutManager.textViewForBeginningOfSelection?.breakUndoCoalescing()
|
||||
let textViews = self.textStorage.layoutManagers.compactMap(\.textViewForBeginningOfSelection)
|
||||
for textView in textViews {
|
||||
textView.breakUndoCoalescing()
|
||||
}
|
||||
|
||||
// trim trailing whitespace if needed
|
||||
if !saveOperation.isAutosave, UserDefaults.standard[.autoTrimsTrailingWhitespace] {
|
||||
textViews.first?.trimTrailingWhitespace(ignoresEmptyLines: !UserDefaults.standard[.trimsWhitespaceOnlyLines])
|
||||
}
|
||||
|
||||
// workaround the issue that invoking the async version super blocks the save process
|
||||
|
Loading…
Reference in New Issue
Block a user