Optimize line ending normalization (fix #1406)

This commit is contained in:
1024jp 2023-11-26 10:43:31 +09:00
parent 12cec17bd1
commit 7aeecd7ede
2 changed files with 5 additions and 1 deletions

View File

@ -7,6 +7,7 @@ Change Log
### Improvements
- Optimize the performance of the normalization of incompatible line endings.
- [beta][trivial] Add device name to quick actions related to Continuity Camera.
- [beta] Localize strings added on CotEditor 4.7.0 to Chinese, Italian, and Turkish.

View File

@ -156,7 +156,10 @@ extension NSMutableAttributedString {
/// - lineEnding: The line ending type with which to replace the target.
final func replaceLineEndings(with lineEnding: LineEnding) {
self.mutableString.replaceOccurrences(of: LineEnding.allRegexPattern, with: lineEnding.string, options: .regularExpression, range: self.range)
// -> Intentionally avoid replacing characters in the mutableString directly,
// because it pots a quantity of small edited notifications,
// which costs high. (2023-11, macOS 14)
self.replaceCharacters(in: self.range, with: self.string.replacingLineEndings(with: lineEnding))
}
}