forked from KeyboardKit/KeyboardKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new autocomplete property to KeyboardAction
- Loading branch information
1 parent
ef65fe6
commit c86c034
Showing
5 changed files
with
70 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
Sources/KeyboardKit/Actions/KeyboardAction+Autocomplete.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// KeyboardAction+Actions.swift | ||
// KeyboardKit | ||
// | ||
// Created by Daniel Saidi on 2021-03-18. | ||
// Copyright © 2021 Daniel Saidi. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public extension KeyboardAction { | ||
|
||
/** | ||
Whether or not the action, when triggered, should apply | ||
autocomplete suggestions where `isAutocomplete` is true. | ||
*/ | ||
var shouldApplyAutocompleteSuggestion: Bool { | ||
switch self { | ||
case .character(let char): return char.isWordDelimiter | ||
case .newLine: return true | ||
case .return: return true | ||
case .space: return true | ||
default: return false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
Tests/KeyboardKitTests/Actions/KeyboardAction+AutocompleteTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// KeyboardAction_AutocompleteTests.swift | ||
// KeyboardKit | ||
// | ||
// Created by Daniel Saidi on 2021-03-18. | ||
// Copyright © 2021 Daniel Saidi. All rights reserved. | ||
// | ||
|
||
import Quick | ||
import Nimble | ||
import KeyboardKit | ||
|
||
class KeyboardAction_AutocompleteTests: QuickSpec { | ||
|
||
override func spec() { | ||
|
||
var actions: [KeyboardAction]! | ||
var delimiterActions: [KeyboardAction]! | ||
|
||
beforeEach { | ||
actions = KeyboardAction.testActions | ||
delimiterActions = String.wordDelimiters.map { .character($0) } | ||
delimiterActions.forEach { actions.append($0) } | ||
} | ||
|
||
describe("should apply autocomplete suggestion") { | ||
|
||
it("is true for word and sentence ending actions") { | ||
var expected = delimiterActions! | ||
expected.append(.newLine) | ||
expected.append(.return) | ||
expected.append(.space) | ||
|
||
actions.forEach { | ||
expect($0.shouldApplyAutocompleteSuggestion).to(equal(expected.contains($0))) | ||
} | ||
} | ||
} | ||
} | ||
} |