@@ -284,7 +284,7 @@ class KeyboardViewController: UIInputViewController {
284
284
285
285
/// Generates an array of the three autosuggest words.
286
286
func getAutosuggestions( ) {
287
- let prefix = pastStringInTextProxy . replacingOccurrences ( of : secondaryPastStringOnDelete , with : " " ) . replacingOccurrences ( of : " " , with : " " )
287
+ let prefix = proxy . documentContextBeforeInput ? . components ( separatedBy : " " ) . secondToLast ( ) ?? " "
288
288
289
289
if prefix. isNumeric {
290
290
completionWords = numericAutosuggestions
@@ -397,9 +397,6 @@ class KeyboardViewController: UIInputViewController {
397
397
autoActionState = . suggest
398
398
proxy. insertText ( " " )
399
399
currentPrefix = " "
400
- secondaryPastStringOnDelete = pastStringInTextProxy
401
- pastStringInTextProxy = proxy. documentContextBeforeInput ?? " "
402
- clearCommandBar ( )
403
400
conditionallyDisplayAnnotation ( )
404
401
}
405
402
@@ -415,14 +412,6 @@ class KeyboardViewController: UIInputViewController {
415
412
@IBOutlet var commandBarShadow : UIButton !
416
413
@IBOutlet var commandBarBlend : UILabel !
417
414
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
-
426
415
/// Deletes in the proxy or command bar given the current constraints.
427
416
func handleDeleteButtonPressed( ) {
428
417
if [ . idle, . selectCommand, . alreadyPlural, . invalid] . contains ( commandState) {
@@ -1541,7 +1530,6 @@ class KeyboardViewController: UIInputViewController {
1541
1530
case " return " :
1542
1531
if ![ . translate, . conjugate, . plural] . contains ( commandState) { // normal return button
1543
1532
proxy. insertText ( " \n " )
1544
- clearCommandBar ( )
1545
1533
} else if commandState == . translate {
1546
1534
queryTranslation ( commandBar: commandBar)
1547
1535
} else if commandState == . conjugate {
@@ -1576,7 +1564,6 @@ class KeyboardViewController: UIInputViewController {
1576
1564
} else if [ . translate, . plural] . contains ( commandState) { // functional commands above
1577
1565
autoActionState = . suggest
1578
1566
commandState = . idle
1579
- clearCommandBar ( )
1580
1567
autoCapAtStartOfProxy ( )
1581
1568
loadKeys ( )
1582
1569
conditionallyDisplayAnnotation ( )
@@ -1685,6 +1672,12 @@ class KeyboardViewController: UIInputViewController {
1685
1672
executeAutoAction ( keyPressed: pluralKey)
1686
1673
1687
1674
case " GetAnnotationInfo " :
1675
+ // Remove all prior annotations.
1676
+ annotationBtns. forEach { $0. removeFromSuperview ( ) }
1677
+ annotationBtns. removeAll ( )
1678
+ annotationSeparators. forEach { $0. removeFromSuperview ( ) }
1679
+ annotationSeparators. removeAll ( )
1680
+
1688
1681
for i in 0 ..< annotationBtns. count {
1689
1682
annotationBtns [ i] . backgroundColor = annotationColors [ i]
1690
1683
}
@@ -1730,9 +1723,13 @@ class KeyboardViewController: UIInputViewController {
1730
1723
1731
1724
handleDeleteButtonPressed ( )
1732
1725
autoCapAtStartOfProxy ( )
1733
- clearCommandBar ( )
1734
1726
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
+ }
1736
1733
conditionallySetAutoActionBtns ( )
1737
1734
} else {
1738
1735
// Shift state if the user presses delete when the prompt is present.
@@ -1776,13 +1773,15 @@ class KeyboardViewController: UIInputViewController {
1776
1773
}
1777
1774
}
1778
1775
1779
- secondaryPastStringOnDelete = pastStringInTextProxy
1780
- pastStringInTextProxy = proxy. documentContextBeforeInput ?? " "
1781
- conditionallyDisplayAnnotation ( )
1782
-
1783
1776
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 ( )
1785
1782
}
1783
+
1784
+ conditionallyDisplayAnnotation ( )
1786
1785
doubleSpacePeriodPossible = true
1787
1786
1788
1787
case " ' " :
@@ -1794,25 +1793,20 @@ class KeyboardViewController: UIInputViewController {
1794
1793
commandBar. text! = ( commandBar. text!. insertPriorToCursor ( char: " ' " ) )
1795
1794
}
1796
1795
changeKeyboardToLetterKeys ( )
1797
- clearCommandBar ( )
1798
1796
1799
1797
case " shift " :
1800
1798
shiftButtonState = shiftButtonState == . normal ? . shift : . normal
1801
1799
loadKeys ( )
1802
- clearCommandBar ( )
1803
1800
capsLockPossible = true
1804
1801
1805
1802
case " 123 " , " .?123 " :
1806
1803
changeKeyboardToNumberKeys ( )
1807
- clearCommandBar ( )
1808
1804
1809
1805
case " #+= " :
1810
1806
changeKeyboardToSymbolKeys ( )
1811
- clearCommandBar ( )
1812
1807
1813
1808
case " ABC " , " АБВ " :
1814
1809
changeKeyboardToLetterKeys ( )
1815
- clearCommandBar ( )
1816
1810
autoCapAtStartOfProxy ( )
1817
1811
1818
1812
case " selectKeyboard " :
@@ -1830,7 +1824,6 @@ class KeyboardViewController: UIInputViewController {
1830
1824
}
1831
1825
if [ . idle, . selectCommand, . alreadyPlural, . invalid] . contains ( commandState) {
1832
1826
proxy. insertText ( keyToDisplay)
1833
- clearCommandBar ( )
1834
1827
} else {
1835
1828
commandBar. text = commandBar. text!. insertPriorToCursor ( char: keyToDisplay)
1836
1829
}
@@ -1916,7 +1909,6 @@ class KeyboardViewController: UIInputViewController {
1916
1909
if touch. tapCount == 2 && originalKey == " shift " && capsLockPossible == true {
1917
1910
shiftButtonState = . caps
1918
1911
loadKeys ( )
1919
- clearCommandBar ( )
1920
1912
conditionallySetAutoActionBtns ( )
1921
1913
}
1922
1914
@@ -1953,7 +1945,6 @@ class KeyboardViewController: UIInputViewController {
1953
1945
shiftButtonState = . shift
1954
1946
loadKeys ( )
1955
1947
}
1956
- clearCommandBar ( )
1957
1948
// Show auto actions if the keyboard states dictate.
1958
1949
conditionallySetAutoActionBtns ( )
1959
1950
}
0 commit comments