mirror of
https://github.com/coteditor/CotEditor.git
synced 2024-10-26 19:10:11 +03:00
Avoid replacing if result of Replace All is 0
This commit is contained in:
parent
d659858db8
commit
535b27f4fc
@ -12,7 +12,9 @@ Develop
|
||||
|
||||
### Improvements
|
||||
|
||||
- Improve the progress indicator of Replace All.
|
||||
- Improve Replace All action:
|
||||
- Avoid recoloring after Replace All if no text replaced.
|
||||
- Improve the progress indicator.
|
||||
- Update “JavaScript” syntax style:
|
||||
- Add “.pac” extension.
|
||||
- Update build environment to Xcode 9 (SDK macOS 10.13).
|
||||
|
@ -235,6 +235,7 @@ final class TextFind {
|
||||
/// - Parameters:
|
||||
/// - replacementString: The string with which to replace.
|
||||
/// - block: The Block enumerates the matches.
|
||||
/// - flag: The current state of the replacing progress.
|
||||
/// - stop: The Block can set the value to true to stop further processing of the array.
|
||||
/// - Returns:
|
||||
/// - replacementItems: ReplacementItem per selectedRange.
|
||||
@ -265,9 +266,12 @@ final class TextFind {
|
||||
}, scopeCompletionHandler: { (scopeRange: NSRange) in
|
||||
block(.foundCount(items.count), &ioStop)
|
||||
|
||||
let length: Int
|
||||
if items.isEmpty {
|
||||
length = scopeRange.length
|
||||
} else {
|
||||
// build replacementString
|
||||
var replacedString = (self.string as NSString).substring(with: scopeRange)
|
||||
|
||||
for item in items.reversed() {
|
||||
block(.replacementProgress, &ioStop)
|
||||
if ioStop { return }
|
||||
@ -276,10 +280,12 @@ final class TextFind {
|
||||
replacedString = (replacedString as NSString).replacingCharacters(in: substringRange, with: item.string)
|
||||
}
|
||||
replacementItems.append(ReplacementItem(string: replacedString, range: scopeRange))
|
||||
length = (replacedString as NSString).length
|
||||
}
|
||||
|
||||
// build selectedRange
|
||||
let locationDelta = zip(selectedRanges, self.selectedRanges).reduce(scopeRange.location) { $0 + ($1.0.length - $1.1.length) }
|
||||
let selectedRange = NSRange(location: locationDelta, length: (replacedString as NSString).length)
|
||||
let selectedRange = NSRange(location: locationDelta, length: length)
|
||||
selectedRanges.append(selectedRange)
|
||||
|
||||
items.removeAll()
|
||||
|
Loading…
Reference in New Issue
Block a user