Skip to content

Commit

Permalink
Rename lineContentRange with lineContentsRange
Browse files Browse the repository at this point in the history
  • Loading branch information
1024jp committed Jul 12, 2024
1 parent fc81c3f commit 2851d79
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions CotEditor/Sources/LineRangeCacheable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ extension LineRangeCacheable {
}


/// Returns the range of the content lines including the given range.
/// Returns the range of the contents 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 because 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 {
/// - Returns: The character range of the contents line.
func lineContentsRange(for range: NSRange) -> NSRange {

let lineRange = self.lineRange(for: range)

Expand Down
2 changes: 1 addition & 1 deletion CotEditor/Sources/TextFinder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ struct TextFindAllResult {
let matchedRange = matches[0]

// build a highlighted line string for result table
let lineRange = lineCounter.lineContentRange(for: matchedRange)
let lineRange = lineCounter.lineContentsRange(for: matchedRange)
let lineString = (textFind.string as NSString).substring(with: lineRange)
let attrLineString = NSMutableAttributedString(string: lineString)
for (color, range) in zip(highlightColors, matches) where !range.isEmpty {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,19 @@ public extension String {
func deleteDuplicateLine(in ranges: [NSRange]) -> EditingContext? {

let string = self as NSString
let lineContentRanges = ranges
let lineContentsRanges = ranges
.map { string.lineRange(for: $0) }
.flatMap { self.lineContentsRanges(for: $0) }
.uniqued
.sorted(\.location)

var replacementRanges: [NSRange] = []
var uniqueLines: [String] = []
for lineContentRange in lineContentRanges {
let line = string.substring(with: lineContentRange)
for lineContentsRange in lineContentsRanges {
let line = string.substring(with: lineContentsRange)

if uniqueLines.contains(line) {
replacementRanges.append(string.lineRange(for: lineContentRange))
replacementRanges.append(string.lineRange(for: lineContentsRange))
} else {
uniqueLines.append(line)
}
Expand Down
10 changes: 5 additions & 5 deletions Tests/LineRangeCacheableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ struct LineRangeCacheableTests {
}


@Test func lineContentRange() {
@Test func lineContentsRange() {

let lineString = LineString("dog \n\n cat \n cow")
#expect(lineString.lineContentRange(for: NSRange(0..<3)) == NSRange(0..<4))
#expect(lineString.lineContentRange(for: NSRange(4..<6)) == NSRange(0..<6))
#expect(lineString.lineContentRange(for: NSRange(5..<6)) == NSRange(5..<6))
#expect(lineString.lineContentRange(for: NSRange(7..<13)) == NSRange(6..<16))
#expect(lineString.lineContentsRange(for: NSRange(0..<3)) == NSRange(0..<4))
#expect(lineString.lineContentsRange(for: NSRange(4..<6)) == NSRange(0..<6))
#expect(lineString.lineContentsRange(for: NSRange(5..<6)) == NSRange(5..<6))
#expect(lineString.lineContentsRange(for: NSRange(7..<13)) == NSRange(6..<16))
}


Expand Down

0 comments on commit 2851d79

Please sign in to comment.