Skip to content

Commit 1ff0c2a

Browse files
committed
#218 fix autoaction triggers and code cleaning
1 parent 922c7d0 commit 1ff0c2a

File tree

3 files changed

+26
-31
lines changed

3 files changed

+26
-31
lines changed

Keyboards/KeyboardsBase/KeyboardViewController.swift

+20-29
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ class KeyboardViewController: UIInputViewController {
284284

285285
/// Generates an array of the three autosuggest words.
286286
func getAutosuggestions() {
287-
let prefix = pastStringInTextProxy.replacingOccurrences(of: secondaryPastStringOnDelete, with: "").replacingOccurrences(of: " ", with: "")
287+
let prefix = proxy.documentContextBeforeInput?.components(separatedBy: " ").secondToLast() ?? ""
288288

289289
if prefix.isNumeric {
290290
completionWords = numericAutosuggestions
@@ -397,9 +397,6 @@ class KeyboardViewController: UIInputViewController {
397397
autoActionState = .suggest
398398
proxy.insertText(" ")
399399
currentPrefix = ""
400-
secondaryPastStringOnDelete = pastStringInTextProxy
401-
pastStringInTextProxy = proxy.documentContextBeforeInput ?? ""
402-
clearCommandBar()
403400
conditionallyDisplayAnnotation()
404401
}
405402

@@ -415,14 +412,6 @@ class KeyboardViewController: UIInputViewController {
415412
@IBOutlet var commandBarShadow: UIButton!
416413
@IBOutlet var commandBarBlend: UILabel!
417414

418-
/// Clears the text found in the command bar.
419-
func clearCommandBar() {
420-
if [.idle, .selectCommand].contains(commandState) {
421-
commandBar.textColor = keyCharColor
422-
commandBar.text = ""
423-
}
424-
}
425-
426415
/// Deletes in the proxy or command bar given the current constraints.
427416
func handleDeleteButtonPressed() {
428417
if [.idle, .selectCommand, .alreadyPlural, .invalid].contains(commandState) {
@@ -1541,7 +1530,6 @@ class KeyboardViewController: UIInputViewController {
15411530
case "return":
15421531
if ![.translate, .conjugate, .plural].contains(commandState) { // normal return button
15431532
proxy.insertText("\n")
1544-
clearCommandBar()
15451533
} else if commandState == .translate {
15461534
queryTranslation(commandBar: commandBar)
15471535
} else if commandState == .conjugate {
@@ -1576,7 +1564,6 @@ class KeyboardViewController: UIInputViewController {
15761564
} else if [.translate, .plural].contains(commandState) { // functional commands above
15771565
autoActionState = .suggest
15781566
commandState = .idle
1579-
clearCommandBar()
15801567
autoCapAtStartOfProxy()
15811568
loadKeys()
15821569
conditionallyDisplayAnnotation()
@@ -1685,6 +1672,12 @@ class KeyboardViewController: UIInputViewController {
16851672
executeAutoAction(keyPressed: pluralKey)
16861673

16871674
case "GetAnnotationInfo":
1675+
// Remove all prior annotations.
1676+
annotationBtns.forEach { $0.removeFromSuperview() }
1677+
annotationBtns.removeAll()
1678+
annotationSeparators.forEach { $0.removeFromSuperview() }
1679+
annotationSeparators.removeAll()
1680+
16881681
for i in 0..<annotationBtns.count {
16891682
annotationBtns[i].backgroundColor = annotationColors[i]
16901683
}
@@ -1730,9 +1723,13 @@ class KeyboardViewController: UIInputViewController {
17301723

17311724
handleDeleteButtonPressed()
17321725
autoCapAtStartOfProxy()
1733-
clearCommandBar()
17341726

1735-
autoActionState = .complete
1727+
// Check if the last character is a space such that the user is deleting multiple spaces and suggest is so.
1728+
if proxy.documentContextBeforeInput?.suffix(" ".count) == " " {
1729+
autoActionState = .suggest
1730+
} else {
1731+
autoActionState = .complete
1732+
}
17361733
conditionallySetAutoActionBtns()
17371734
} else {
17381735
// Shift state if the user presses delete when the prompt is present.
@@ -1776,13 +1773,15 @@ class KeyboardViewController: UIInputViewController {
17761773
}
17771774
}
17781775

1779-
secondaryPastStringOnDelete = pastStringInTextProxy
1780-
pastStringInTextProxy = proxy.documentContextBeforeInput ?? ""
1781-
conditionallyDisplayAnnotation()
1782-
17831776
if proxy.documentContextBeforeInput?.suffix(" ".count) == " " {
1784-
clearCommandBar()
1777+
// Remove all prior annotations.
1778+
annotationBtns.forEach { $0.removeFromSuperview() }
1779+
annotationBtns.removeAll()
1780+
annotationSeparators.forEach { $0.removeFromSuperview() }
1781+
annotationSeparators.removeAll()
17851782
}
1783+
1784+
conditionallyDisplayAnnotation()
17861785
doubleSpacePeriodPossible = true
17871786

17881787
case "'":
@@ -1794,25 +1793,20 @@ class KeyboardViewController: UIInputViewController {
17941793
commandBar.text! = (commandBar.text!.insertPriorToCursor(char: "'"))
17951794
}
17961795
changeKeyboardToLetterKeys()
1797-
clearCommandBar()
17981796

17991797
case "shift":
18001798
shiftButtonState = shiftButtonState == .normal ? .shift : .normal
18011799
loadKeys()
1802-
clearCommandBar()
18031800
capsLockPossible = true
18041801

18051802
case "123", ".?123":
18061803
changeKeyboardToNumberKeys()
1807-
clearCommandBar()
18081804

18091805
case "#+=":
18101806
changeKeyboardToSymbolKeys()
1811-
clearCommandBar()
18121807

18131808
case "ABC", "АБВ":
18141809
changeKeyboardToLetterKeys()
1815-
clearCommandBar()
18161810
autoCapAtStartOfProxy()
18171811

18181812
case "selectKeyboard":
@@ -1830,7 +1824,6 @@ class KeyboardViewController: UIInputViewController {
18301824
}
18311825
if [.idle, .selectCommand, .alreadyPlural, .invalid].contains(commandState) {
18321826
proxy.insertText(keyToDisplay)
1833-
clearCommandBar()
18341827
} else {
18351828
commandBar.text = commandBar.text!.insertPriorToCursor(char: keyToDisplay)
18361829
}
@@ -1916,7 +1909,6 @@ class KeyboardViewController: UIInputViewController {
19161909
if touch.tapCount == 2 && originalKey == "shift" && capsLockPossible == true {
19171910
shiftButtonState = .caps
19181911
loadKeys()
1919-
clearCommandBar()
19201912
conditionallySetAutoActionBtns()
19211913
}
19221914

@@ -1953,7 +1945,6 @@ class KeyboardViewController: UIInputViewController {
19531945
shiftButtonState = .shift
19541946
loadKeys()
19551947
}
1956-
clearCommandBar()
19571948
// Show auto actions if the keyboard states dictate.
19581949
conditionallySetAutoActionBtns()
19591950
}

Keyboards/KeyboardsBase/ScribeFunctionality/CommandVariables.swift

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ var numericAutosuggestions = [String]()
2727

2828
var currentPrefix: String = ""
2929
var pastStringInTextProxy: String = ""
30-
var secondaryPastStringOnDelete: String = ""
3130
var completionWords = [String]()
3231

3332
// A larger vertical bar than the normal | key for the cursor.

Keyboards/LanguageKeyboards/German/Data/autosuggestions.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
{
2+
"ich": [
3+
"muss",
4+
"bin",
5+
"kann"
6+
],
27
"der": [
38
"Name",
49
"Stadt",
@@ -4998,4 +5003,4 @@
49985003
"die",
49995004
"ist"
50005005
]
5001-
}
5006+
}

0 commit comments

Comments
 (0)