Skip to content

Commit dcd2e33

Browse files
update CI, some new docs
1 parent 91dd9a6 commit dcd2e33

File tree

6 files changed

+45
-11
lines changed

6 files changed

+45
-11
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ jobs:
1414
runs-on: macOS-latest
1515
steps:
1616
- uses: actions/checkout@v1
17-
- name: xcodebuild test
18-
run: set -o pipefail && xcodebuild test -scheme TextViewPlus -destination "platform=macOS" | xcpretty
17+
- name: swift test
18+
run: swift test
19+
- name: carthage
20+
run: carthage build --no-skip-current

.gitignore

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1-
Carthage/
2-
.build
1+
.DS_Store
2+
/.build
3+
/Carthage
4+
/Packages
5+
xcuserdata/
6+
DerivedData/
7+
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
[![Github CI](https://github.com/ChimeHQ/TextViewPlus/workflows/CI/badge.svg)](https://github.com/ChimeHQ/TextViewPlus/actions)
22
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg)](https://github.com/Carthage/Carthage)
3-
![](https://img.shields.io/badge/Swift-5.0-orange.svg)
43

54
# TextViewPlus
65

7-
TextViewPlus is a collection of utilities for making it easier to work with NSTextView.
6+
TextViewPlus is a collection of utilities for making it easier to work with `NSTextView`.
87

98
## Integration
109

@@ -26,7 +25,7 @@ github "ChimeHQ/TextViewPlus"
2625

2726
**Geometry**
2827

29-
Wrappers around the underlying NSLayoutManager, but with a much more convenient API.
28+
Wrappers around the underlying `NSLayoutManager`, but with a much more convenient API.
3029

3130
```swift
3231
func enumerateLineFragments(for range: NSRange, block: (NSRect, NSRange) -> Void)
@@ -72,7 +71,7 @@ func boundingSelectionRects(forRange range: NSRange) -> [NSRect]
7271

7372
**Attributed Strings**
7473

75-
Programmtic modification of the underlying attributed string in the NSTextStorage, with support for delegate callbacks and undo.
74+
Programmtic modification of the underlying attributed string in the `NSTextStorage`, with support for delegate callbacks and undo.
7675

7776
```swift
7877
func replaceCharacters(in range: NSRange, with attributedString: NSAttributedString)
@@ -83,7 +82,7 @@ func replaceString(in range: NSRange, with attributedString: NSAttributedString)
8382

8483
**Behavior**
8584

86-
Changing NSTextView behaviors can be tricky, and often involve complex interactions with the whole system (NSLayoutManager, NSTextContainer, NSScrollView, etc).
85+
Changing `NSTextView` behaviors can be tricky, and often involve complex interactions with the whole system (`NSLayoutManager`, `NSTextContainer`, `NSScrollView`, etc).
8786

8887
```swift
8988
public var wrapsTextToHorizontalBounds: Bool

TextViewPlus/NSTextView+Selection.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Foundation
1010
import class AppKit.NSTextView
1111

1212
extension NSTextView {
13+
/// All the selected ranges, as NSRange instances
1314
public var selectedTextRanges: [NSRange] {
1415
get {
1516
return selectedRanges.map({ $0.rangeValue })
@@ -19,6 +20,9 @@ extension NSTextView {
1920
}
2021
}
2122

23+
/// A single range representing a single, continuous selection
24+
///
25+
/// This method returns nil if there isn't exactly one selection range.
2226
public var selectedContinuousRange: NSRange? {
2327
let ranges = selectedTextRanges
2428
if ranges.count != 1 {
@@ -28,6 +32,10 @@ extension NSTextView {
2832
return ranges.first!
2933
}
3034

35+
/// A singlel location representing a single, zero-length selection
36+
///
37+
/// This method returns nil if there is more than one selected range,
38+
/// or if that range has a non-zero length.
3139
public var insertionLocation: Int? {
3240
guard let range = selectedContinuousRange else {
3341
return nil

TextViewPlus/TextViewPlus.xcconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
PRODUCT_NAME = TextViewPlus
1313
PRODUCT_BUNDLE_IDENTIFIER = com.chimehq.TextViewPlus
1414
PRODUCT_MODULE_NAME = TextViewPlus
15-
CURRENT_PROJECT_VERSION = 6
16-
MARKETING_VERSION = 1.0.4
15+
CURRENT_PROJECT_VERSION = 7
16+
MARKETING_VERSION = 1.0.5
1717

1818
INFOPLIST_FILE = TextViewPlus/Info.plist
1919
FRAMEWORK_SEARCH_PATHS = $(PROJECT_DIR)/Carthage/Build/Mac $(PROJECT_DIR)/Carthage/Build/Mac/Static

TextViewPlusTests/TextViewPlusTests.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,24 @@ extension TextViewPlusTests {
6262
XCTAssertEqual(textView.selectedRanges, [NSValue(range: NSRange(0..<0))])
6363
XCTAssertEqual(textView.selectedTextRanges, [NSRange(0..<0)])
6464
}
65+
66+
func testContinuousSelectionRanges() {
67+
let textView = TestableTextView(string: "abc")
68+
69+
XCTAssertEqual(textView.selectedContinuousRange, NSRange(3..<3))
70+
71+
textView.selectedTextRanges = [NSRange(0..<1), NSRange(2..<3)]
72+
73+
XCTAssertNil(textView.selectedContinuousRange)
74+
}
75+
76+
func testInsertionLocation() {
77+
let textView = TestableTextView(string: "abc")
78+
79+
XCTAssertEqual(textView.insertionLocation, 3)
80+
81+
textView.selectedTextRanges = [NSRange(0..<1)]
82+
83+
XCTAssertNil(textView.insertionLocation)
84+
}
6585
}

0 commit comments

Comments
 (0)