Fix target range of CSVSortPattern

This commit is contained in:
1024jp 2020-02-10 16:53:56 +09:00
parent 84f4a368d3
commit 0565350b18
3 changed files with 21 additions and 4 deletions

View File

@ -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.

View File

@ -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)
}

View File

@ -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))
}
}