Skip to content

Commit ac1b50c

Browse files
committed
Update Conformances
1 parent a678f18 commit ac1b50c

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Views/MockCompletionDelegate.swift

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ class MockCompletionDelegate: CodeSuggestionDelegate, ObservableObject {
6060
}
6161
}
6262

63-
private func randomSuggestions() -> [Suggestion] {
64-
let count = Int.random(in: 0..<20)
63+
private func randomSuggestions(_ count: Int? = nil) -> [Suggestion] {
64+
let count = count ?? Int.random(in: 0..<20)
6565
var suggestions: [Suggestion] = []
6666
for _ in 0..<count {
6767
let randomString = (0..<Int.random(in: 1..<text.count)).map {
@@ -72,6 +72,8 @@ class MockCompletionDelegate: CodeSuggestionDelegate, ObservableObject {
7272
return suggestions
7373
}
7474

75+
var moveCount = 0
76+
7577
func completionSuggestionsRequested(
7678
textView: TextViewController,
7779
cursorPosition: CursorPosition
@@ -84,17 +86,22 @@ class MockCompletionDelegate: CodeSuggestionDelegate, ObservableObject {
8486
textView: TextViewController,
8587
cursorPosition: CursorPosition
8688
) -> [CodeSuggestionEntry]? {
87-
if Bool.random() {
88-
randomSuggestions()
89-
} else {
90-
nil
89+
moveCount += 1
90+
switch moveCount {
91+
case 1:
92+
return randomSuggestions(2)
93+
case 2:
94+
return randomSuggestions(20)
95+
default:
96+
moveCount = 0
97+
return nil
9198
}
9299
}
93100

94101
func completionWindowApplyCompletion(
95102
item: CodeSuggestionEntry,
96103
textView: TextViewController,
97-
cursorPosition: CursorPosition
104+
cursorPosition: CursorPosition?
98105
) {
99106
guard let suggestion = item as? Suggestion else {
100107
return

Sources/CodeEditSourceEditor/CodeSuggestion/Model/CodeSuggestionDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public protocol CodeSuggestionDelegate: AnyObject {
2525
func completionWindowApplyCompletion(
2626
item: CodeSuggestionEntry,
2727
textView: TextViewController,
28-
cursorPosition: CursorPosition
28+
cursorPosition: CursorPosition?
2929
)
3030
// Optional
3131
func completionWindowDidSelect(item: CodeSuggestionEntry)

0 commit comments

Comments
 (0)