Skip to content

Commit

Permalink
Add new autocomplete property to KeyboardAction
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsaidi committed Mar 18, 2021
1 parent ef65fe6 commit c86c034
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 3 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Breaking changes can still occur in minor versions, if the alternative is to not
* `AutocompleteToolbar` has a new `itemBuilder` initializer.
* `AutocompleteToolbarItem` is a new view that replicates a native autocomplete item.
* `AutocompleteToolbarItemText` is a new view that replicates the text of a native autocomplete item.
* `KeyboardAction` has a new `shouldApplyAutocompleteSuggestion` property.
* `KeyboardLocale` now implementes `Identifiable`.
* `KeyboardLocale` has new `flag`, `id` and `localeIdentifier` properties.
* `KeyboardInputViewController` has a new `autocompleteSuggestionProvider` property.
Expand Down
26 changes: 26 additions & 0 deletions Sources/KeyboardKit/Actions/KeyboardAction+Autocomplete.swift
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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import Foundation

public extension KeyboardLocale {

@available(*, deprecated, renamed: "identifier")
@available(*, deprecated, renamed: "id")
var key: String { id }
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// KeyboardActionRowTest.swift
// KeyboardAction+AliasesTests.swift
// KeyboardKit
//
// Created by Daniel Saidi on 2019-07-04.
Expand All @@ -10,7 +10,7 @@ import Quick
import Nimble
import KeyboardKit

class KeyboardActionRowTest: QuickSpec {
class KeyboardAction_AliasesTests: QuickSpec {

override func spec() {

Expand Down
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)))
}
}
}
}
}

0 comments on commit c86c034

Please sign in to comment.