mirror of
https://github.com/coteditor/CotEditor.git
synced 2024-09-11 11:25:57 +03:00
Fix crash on Find All including line ending
This commit is contained in:
parent
294fc95551
commit
c6b40dd9ee
@ -12,6 +12,7 @@ Change Log
|
||||
|
||||
### Fixes
|
||||
|
||||
- Fix an issue that the application crashed when performing the Find All command with a specific find string.
|
||||
- Fix an issue that the Settings window disappeared when the application is inactive.
|
||||
- [trivial] Fix an issue that unwanted debug log appeared in the Console.
|
||||
|
||||
|
@ -104,6 +104,28 @@ extension LineRangeCacheable {
|
||||
}
|
||||
|
||||
|
||||
/// Return the range of the content lines including the given range.
|
||||
///
|
||||
/// Because this method count up all the line ranges up to the given index when not cached yet,
|
||||
/// there is a large performance disadvantage when just a single line range is needed.
|
||||
/// In addition, this method actually doesn't has much performance advantage becaouse it checks the line ending range.
|
||||
///
|
||||
/// - Parameter range: The range of character for finding the line range.
|
||||
/// - Returns: The character range of the content line.
|
||||
func lineContentRange(for range: NSRange) -> NSRange {
|
||||
|
||||
let lineRange = self.lineRange(for: range)
|
||||
|
||||
guard range.upperBound < lineRange.upperBound else { return lineRange }
|
||||
|
||||
let lineEndingRange = self.string.range(of: "\\R", options: [.backwards, .anchored, .regularExpression], range: lineRange)
|
||||
|
||||
guard !lineEndingRange.isNotFound else { return lineRange }
|
||||
|
||||
return NSRange(lineRange.lowerBound..<lineEndingRange.lowerBound)
|
||||
}
|
||||
|
||||
|
||||
/// Return the index of the first character of the line touched by the given index.
|
||||
///
|
||||
/// Because this method count up all the line ranges up to the given index when not cached yet,
|
||||
|
@ -540,8 +540,8 @@ final class TextFinder {
|
||||
let matchedRange = matches[0]
|
||||
|
||||
// build a highlighted line string for result table
|
||||
let lineRange = lineCounter.lineRange(for: matchedRange)
|
||||
let lineString = (textFind.string as NSString).substring(with: lineRange).replacing(/\R$/, with: "")
|
||||
let lineRange = lineCounter.lineContentRange(for: matchedRange)
|
||||
let lineString = (textFind.string as NSString).substring(with: lineRange)
|
||||
let attrLineString = NSMutableAttributedString(string: lineString)
|
||||
for (index, range) in matches.enumerated() where !range.isEmpty {
|
||||
attrLineString.addAttribute(.backgroundColor,
|
||||
|
Loading…
Reference in New Issue
Block a user