mirror of
https://github.com/coteditor/CotEditor.git
synced 2024-09-11 11:25:57 +03:00
Fix target range of CSVSortPattern
This commit is contained in:
parent
84f4a368d3
commit
0565350b18
@ -20,6 +20,7 @@ Change Log
|
||||
- Fix an issue where unescaping replacement string in the regular expression replacement failed with specific text patterns.
|
||||
- Fix an issue where the editor's line height and tab width in the opened windows did not update even the setting is changed.
|
||||
- Fix an issue where the application crashed when moving lines down under specific conditions.
|
||||
- Fix an issue where the “Sort by Pattern” with column sort key dropped the last character from the sort key string.
|
||||
- Fix an issue in scripting where settings some properties, such as `tab width`, `tab expands` and `wrap lines`, in the document creation phase were ignored.
|
||||
- Improve stability.
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
//
|
||||
// ---------------------------------------------------------------------------
|
||||
//
|
||||
// © 2018 1024jp
|
||||
// © 2018-2020 1024jp
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
@ -135,11 +135,11 @@ final class CSVSortPattern: NSObject, SortPattern {
|
||||
end = line.index(start, offsetBy: component.count)
|
||||
|
||||
range = start..<end
|
||||
if let trimmedStart = component.firstIndex(where: { $0 != " " }) {
|
||||
if let trimmedStart = component.firstIndex(where: { !$0.isWhitespace }) {
|
||||
let offset = component.distance(from: component.startIndex, to: trimmedStart)
|
||||
range = line.index(start, offsetBy: offset)..<range.upperBound
|
||||
}
|
||||
if let trimmedEnd = component.lastIndex(where: { $0 != " " }) {
|
||||
if let trimmedEnd = component.lastIndex(where: { $0.isWhitespace }) {
|
||||
let offset = component.distance(from: component.startIndex, to: trimmedEnd)
|
||||
range = range.lowerBound..<line.index(start, offsetBy: offset)
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
//
|
||||
// ---------------------------------------------------------------------------
|
||||
//
|
||||
// © 2018 1024jp
|
||||
// © 2018-2020 1024jp
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
@ -86,5 +86,21 @@ final class LineSortTests: XCTestCase {
|
||||
|
||||
XCTAssertEqual(pattern.sort(self.lines, options: options), result)
|
||||
}
|
||||
|
||||
|
||||
func testTargetRange() {
|
||||
|
||||
let string = "dog"
|
||||
XCTAssertEqual(EntireLineSortPattern().range(for: string), string.startIndex..<string.endIndex)
|
||||
XCTAssertEqual(CSVSortPattern().range(for: string), string.startIndex..<string.endIndex)
|
||||
XCTAssertNil(RegularExpressionSortPattern().range(for: string))
|
||||
|
||||
XCTAssertEqual(CSVSortPattern().range(for: ""), Range(NSRange(0..<0), in: ""))
|
||||
|
||||
let csvString = " dog , dog cow "
|
||||
let pattern = CSVSortPattern()
|
||||
pattern.column = 2
|
||||
XCTAssertEqual(pattern.range(for: csvString), Range(NSRange(8..<15), in: csvString))
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user