Skip to content

Commit

Permalink
#283 repeat function for emoji complete and suggest
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtavis committed Apr 7, 2023
1 parent 97c0afb commit 4ddf305
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Emojis for the following are chosen based on [gitmoji](https://gitmoji.dev/).
<!-- Scribe data is now loaded into SQLite database tables to make data reference less memory intensive and mitigate crashes. -->

- Emoji autocompletions and autosuggestions are now available as the user types.
- The user can also repeat amoji autocompletions and autosuggestions.
- Added action to command bar information icon.
- Added highlight for autocompletion if it is the word typed.
- If a word is the only autosuggestion, hitting the space bar inserts the suggestion. Added undo functionality if the user does not want the completion.
Expand Down
31 changes: 25 additions & 6 deletions Keyboards/KeyboardsBase/KeyboardViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,10 @@ class KeyboardViewController: UIInputViewController {
// Disable the third auto action button if we'll have emoji suggestions.
if emojiKeywords[currentPrefix.lowercased()].exists() {
emojisToDisplayArray = [String]()
currentEmojiTriggerWord = currentPrefix.lowercased()
if emojiKeywords[currentPrefix.lowercased()][1].exists() {
for i in 0..<2 {
let emojiDesc = emojiKeywords[currentPrefix.lowercased()][i]
let emojiDesc = emojiKeywords[currentEmojiTriggerWord][i]
let emoji = emojiDesc["emoji"].rawValue as! String
emojisToDisplayArray.append(emoji)
}
Expand All @@ -362,7 +363,7 @@ class KeyboardViewController: UIInputViewController {
emojiDivider.backgroundColor = UIColor(cgColor: commandBarBorderColor)
}
} else {
let emojiDesc = emojiKeywords[currentPrefix.lowercased()][0]
let emojiDesc = emojiKeywords[currentEmojiTriggerWord][0]
let emoji = emojiDesc["emoji"].rawValue as! String
emojisToDisplayArray.append(emoji)

Expand Down Expand Up @@ -428,6 +429,10 @@ class KeyboardViewController: UIInputViewController {
separatedBy: " "
).secondToLast() ?? ""

if emojiAutoActionRepeatPossible == true {
prefix = currentEmojiTriggerWord
}

// If there's a line break, take the word after it.
if prefix.contains("\n") {
prefix = prefix.components(
Expand Down Expand Up @@ -490,9 +495,10 @@ class KeyboardViewController: UIInputViewController {
// Disable the third auto action button if we'll have emoji suggestions.
if emojiKeywords[prefix.lowercased()].exists() {
emojisToDisplayArray = [String]()
currentEmojiTriggerWord = prefix.lowercased()
if emojiKeywords[prefix.lowercased()][1].exists() {
for i in 0..<2 {
let emojiDesc = emojiKeywords[prefix.lowercased()][i]
let emojiDesc = emojiKeywords[currentEmojiTriggerWord][i]
let emoji = emojiDesc["emoji"].rawValue as! String
emojisToDisplayArray.append(emoji)
}
Expand All @@ -505,7 +511,7 @@ class KeyboardViewController: UIInputViewController {
emojiDivider.backgroundColor = UIColor(cgColor: commandBarBorderColor)
}
} else {
let emojiDesc = emojiKeywords[prefix.lowercased()][0]
let emojiDesc = emojiKeywords[currentEmojiTriggerWord][0]
let emoji = emojiDesc["emoji"].rawValue as! String
emojisToDisplayArray.append(emoji)

Expand Down Expand Up @@ -612,15 +618,23 @@ class KeyboardViewController: UIInputViewController {

clearPrefixFromTextFieldProxy()
emojisToDisplayArray = [String]()
// Remove the space from the previous auto action or replace the current prefix.
if emojiAutoActionRepeatPossible == true && (keyPressed == emojiKey1 || keyPressed == emojiKey2) {
proxy.deleteBackward()
} else {
currentPrefix = ""
}
proxy.insertText(keyPressed.titleLabel?.text ?? "")
autoActionState = .suggest
proxy.insertText(" ")
currentPrefix = ""
autoActionState = .suggest
if shiftButtonState == .shift {
shiftButtonState = .normal
loadKeys()
}
conditionallyDisplayAnnotation()
if keyPressed == emojiKey1 || keyPressed == emojiKey2 {
emojiAutoActionRepeatPossible = true
}
}

// The background for the Scribe command elements.
Expand Down Expand Up @@ -2179,6 +2193,11 @@ class KeyboardViewController: UIInputViewController {
loadKeys()
}

// Reset emoji repeat functionality.
if !["EmojiKey1", "EmojiKey2"].contains(originalKey) {
emojiAutoActionRepeatPossible = false
}

// Add partitions and show auto actions if the keyboard states dictate.
conditionallyShowAutoActionPartitions()
conditionallySetAutoActionBtns()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ var doubleSpacePeriodPossible = false
var autoAction1Visible = true
var autoAction3Visible = true
var emojiAutoActionVisible = false
var currentEmojiTriggerWord = ""
var emojiAutoActionRepeatPossible = false
var shouldHighlightFirstCompletion = false
var allowUndo = false
var previousWord = ""
Expand Down

0 comments on commit 4ddf305

Please sign in to comment.