1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-24 22:33:52 +03:00

GH-666 Rename

This commit is contained in:
Tae Won Ha 2018-10-04 21:36:41 +02:00
parent 7917a4f150
commit 996174e8e5
3 changed files with 23 additions and 23 deletions

View File

@ -184,7 +184,7 @@ extension NvimView {
}
if replacementRange != .notFound {
guard let newMarkedPosition = self.ugrid.position(
guard let newMarkedPosition = self.ugrid.firstPosition(
fromFlatCharIndex: replacementRange.location
) else {
return
@ -278,7 +278,7 @@ extension NvimView {
}
guard
let position = self.ugrid.position(
let position = self.ugrid.firstPosition(
fromFlatCharIndex: aRange.location
),
let inclusiveEndPosition = self.ugrid.lastPosition(
@ -316,7 +316,7 @@ extension NvimView {
public func firstRect(
forCharacterRange aRange: NSRange, actualRange: NSRangePointer?
) -> NSRect {
guard let position = self.ugrid.position(
guard let position = self.ugrid.firstPosition(
fromFlatCharIndex: aRange.location
) else {
return CGRect.zero

View File

@ -82,7 +82,7 @@ final class UGrid: CustomStringConvertible {
}
}
func position(from flattenedIndex: Int) -> Position {
func position(fromOneDimCellIndex flattenedIndex: Int) -> Position {
let row = min(
self.size.height - 1,
max(0, Int(floor(Double(flattenedIndex) / Double(self.size.width))))
@ -95,11 +95,11 @@ final class UGrid: CustomStringConvertible {
return Position(row: row, column: col)
}
func flattenedCellIndex(forRow row: Int, column: Int) -> Int {
func oneDimCellIndex(forRow row: Int, column: Int) -> Int {
return row * self.size.width + column
}
func flattenedCellIndex(forPosition position: Position) -> Int {
func oneDimCellIndex(forPosition position: Position) -> Int {
return position.row * self.size.width + position.column
}
@ -107,7 +107,7 @@ final class UGrid: CustomStringConvertible {
return self.cells[position.row][position.column].flatCharIndex
}
func position(fromFlatCharIndex index: Int) -> Position? {
func firstPosition(fromFlatCharIndex index: Int) -> Position? {
for (rowIndex, row) in self.cells.enumerated() {
if let column = row.firstIndex(where: { $0.flatCharIndex == index }) {
return Position(row: rowIndex, column: column)
@ -311,7 +311,7 @@ final class UGrid: CustomStringConvertible {
var delta = 0
if rowStart > 0 {
delta = self.cells[rowStart - 1][self.size.width - 1].flatCharIndex
- self.flattenedCellIndex(forRow: rowStart - 1,
- self.oneDimCellIndex(forRow: rowStart - 1,
column: self.size.width - 1)
}
@ -321,7 +321,7 @@ final class UGrid: CustomStringConvertible {
delta -= 1
}
self.cells[row][column].flatCharIndex
= self.flattenedCellIndex(forRow: row, column: column) + delta
= self.oneDimCellIndex(forRow: row, column: column) + delta
}
}
}

View File

@ -156,42 +156,42 @@ class UGridTest: XCTestCase {
func testFlattenedIndex() {
self.ugrid.resize(Size(width: 20, height: 10))
expect(
self.ugrid.flattenedCellIndex(forPosition: Position(row: 0, column: 0))
self.ugrid.oneDimCellIndex(forPosition: Position(row: 0, column: 0))
).to(equal(0))
expect(
self.ugrid.flattenedCellIndex(forPosition: Position(row: 0, column: 5))
self.ugrid.oneDimCellIndex(forPosition: Position(row: 0, column: 5))
).to(equal(5))
expect(
self.ugrid.flattenedCellIndex(forPosition: Position(row: 1, column: 0))
self.ugrid.oneDimCellIndex(forPosition: Position(row: 1, column: 0))
).to(equal(20))
expect(
self.ugrid.flattenedCellIndex(forPosition: Position(row: 1, column: 5))
self.ugrid.oneDimCellIndex(forPosition: Position(row: 1, column: 5))
).to(equal(25))
expect(
self.ugrid.flattenedCellIndex(forPosition: Position(row: 9, column: 0))
self.ugrid.oneDimCellIndex(forPosition: Position(row: 9, column: 0))
).to(equal(180))
expect(
self.ugrid.flattenedCellIndex(forPosition: Position(row: 9, column: 19))
self.ugrid.oneDimCellIndex(forPosition: Position(row: 9, column: 19))
).to(equal(199))
}
func testPositionFromFlattenedIndex() {
self.ugrid.resize(Size(width: 20, height: 10))
expect(self.ugrid.position(from: 0))
expect(self.ugrid.position(fromOneDimCellIndex: 0))
.to(equal(Position(row: 0, column: 0)))
expect(self.ugrid.position(from: 5))
expect(self.ugrid.position(fromOneDimCellIndex: 5))
.to(equal(Position(row: 0, column: 5)))
expect(self.ugrid.position(from: 20))
expect(self.ugrid.position(fromOneDimCellIndex: 20))
.to(equal(Position(row: 1, column: 0)))
expect(self.ugrid.position(from: 25))
expect(self.ugrid.position(fromOneDimCellIndex: 25))
.to(equal(Position(row: 1, column: 5)))
expect(self.ugrid.position(from: 180))
expect(self.ugrid.position(fromOneDimCellIndex: 180))
.to(equal(Position(row: 9, column: 0)))
expect(self.ugrid.position(from: 199))
expect(self.ugrid.position(fromOneDimCellIndex: 199))
.to(equal(Position(row: 9, column: 19)))
expect(self.ugrid.position(from: 418))
expect(self.ugrid.position(fromOneDimCellIndex: 418))
.to(equal(Position(row: 9, column: 18)))
expect(self.ugrid.position(from: 419))
expect(self.ugrid.position(fromOneDimCellIndex: 419))
.to(equal(Position(row: 9, column: 19)))
}