Skip to content

Commit

Permalink
Fix selection when highlighting a word
Browse files Browse the repository at this point in the history
  • Loading branch information
soffes committed Jun 22, 2016
1 parent bbdb01b commit 8e24c00
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Sources/SelectionController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ struct SelectionController {
// Inserting
if replacementLength > 0 {

if selection.location == replacementRange.location {
return NSRange(location: selection.location + replacementLength, length: 0)
}

// Shift selection
if replacementRange.max < output.location {
output.location += replacementLength - replacementRange.length
Expand Down
9 changes: 9 additions & 0 deletions Tests/SelectionControllerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ class SelectionControllerTests: XCTestCase {
XCTAssertEqual(NSRange(location: 10, length: 9), output)
}

func testReplaceAll() {
let output = SelectionController.adjust(
selection: NSRange(location: 6, length: 5),
replacementRange: NSRange(location: 6, length: 5),
replacementLength: 1
)
XCTAssertEqual(NSRange(location: 7, length: 0), output)
}


// MARK: - Invalid Input Tests

Expand Down

0 comments on commit 8e24c00

Please sign in to comment.