-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#371] Add functionality for new keyboard expanded layout #373
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// | ||
// Scribe | ||
// | ||
|
||
struct SpecialKeys { | ||
|
||
static let indent = "indent" | ||
static let capsLock = "capslock" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,7 +65,7 @@ class KeyboardKey: UIButton { | |
} else { | ||
capsKey = key | ||
} | ||
let keyToDisplay = shiftButtonState == .normal ? key : capsKey | ||
let keyToDisplay = shiftButtonState == .shift || capsLockButtonState == .locked ? capsKey : key | ||
setTitleColor(keyCharColor, for: .normal) | ||
layer.setValue(key, forKey: "original") | ||
layer.setValue(keyToDisplay, forKey: "keyToDisplay") | ||
|
@@ -256,22 +256,14 @@ class KeyboardKey: UIButton { | |
if key == "ABC" || key == "АБВ" { | ||
layer.setValue(true, forKey: "isSpecial") | ||
widthAnchor.constraint(equalToConstant: numSymKeyWidth * 1).isActive = true | ||
} else if key == "delete" | ||
|| key == "#+=" | ||
|| key == "shift" | ||
|| key == "selectKeyboard" | ||
{ | ||
} else if ["delete", "#+=", "shift", "selectKeyboard", SpecialKeys.indent, SpecialKeys.capsLock].contains(key) { | ||
layer.setValue(true, forKey: "isSpecial") | ||
widthAnchor.constraint(equalToConstant: numSymKeyWidth * 1).isActive = true | ||
} else if key == "123" | ||
|| key == ".?123" | ||
|| key == "return" | ||
|| key == "hideKeyboard" | ||
{ | ||
} else if ["123", ".?123", "return", "hideKeyboard"].contains(key) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Appreciate you fixing these formatting/logic errors! 🙏 |
||
if key == "return" | ||
&& (controllerLanguage == "Portuguese" || controllerLanguage == "Italian" || commandState == .translate) | ||
&& row == 1 | ||
&& DeviceType.isPad | ||
&& (controllerLanguage == "Portuguese" || controllerLanguage == "Italian" || commandState == .translate) | ||
&& row == 1 | ||
&& DeviceType.isPad | ||
{ | ||
layer.setValue(true, forKey: "isSpecial") | ||
widthAnchor.constraint(equalToConstant: numSymKeyWidth * 1.5).isActive = true | ||
|
@@ -291,25 +283,46 @@ class KeyboardKey: UIButton { | |
} else if DeviceType.isPad { | ||
adjustPadKeyWidth() | ||
} | ||
} | ||
|
||
/// Adjusts the style of the button based on different states | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor nit that I'm noting here is that we'd like this to be a complete sentence with a period :) I can get it though! |
||
func adjustButtonStyle() { | ||
guard let isSpecial = layer.value(forKey: "isSpecial") as? Bool else { return } | ||
|
||
if key == "shift" { | ||
// Switch the shift key icon given its state. | ||
switch key { | ||
case SpecialKeys.indent: | ||
backgroundColor = specialKeyColor | ||
|
||
case SpecialKeys.capsLock: | ||
switch capsLockButtonState { | ||
|
||
case .normal: | ||
backgroundColor = specialKeyColor | ||
styleIconBtn(btn: self, color: UIColor.label, iconName: "capslock") | ||
|
||
case .locked: | ||
backgroundColor = keyPressedColor | ||
styleIconBtn(btn: self, color: UIColor.label, iconName: "capslock.fill") | ||
} | ||
|
||
case "shift": | ||
if shiftButtonState == .shift { | ||
backgroundColor = keyPressedColor | ||
styleIconBtn(btn: self, color: UIColor.label, iconName: "shift.fill") | ||
} else if shiftButtonState == .caps { | ||
backgroundColor = keyPressedColor | ||
styleIconBtn(btn: self, color: UIColor.label, iconName: "capslock.fill") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Losing this line is disabling an indication that we're in caps lock on iPhones :) |
||
} else { | ||
backgroundColor = specialKeyColor | ||
} | ||
} else if key == "return" && [.translate, .conjugate, .plural].contains(commandState) { | ||
// Color the return key depending on if it's being used as enter for commands. | ||
backgroundColor = commandKeyColor | ||
} else if isSpecial { | ||
backgroundColor = specialKeyColor | ||
|
||
case "return": | ||
if [.translate, .conjugate, .plural].contains(commandState) { | ||
// Color the return key depending on if it's being used as enter for commands. | ||
backgroundColor = commandKeyColor | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need the else back here for one bug I'm about to mention such that we get There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a default case which should handle the |
||
|
||
default: | ||
if isSpecial { | ||
backgroundColor = specialKeyColor | ||
} | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,9 @@ var keysThatAreSlightlyLarger = [ | |
"chevron.right", | ||
"shift", | ||
"shift.fill", | ||
"capslock", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again the dedication here is amazing. Looking into and finding A basic ask would be if you had ideas for how we can improve the code base, it'd be great if you could open some issues. Anything that you've seen that might be some solid refactoring would be very welcome! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point 🤔 I'll do a quick sweep over the codebase and open a few issues for code quality ^^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks so much, @damien-rivet! Always looking for some |
||
"capslock.fill", | ||
"arrow.forward.to.line", | ||
"arrowtriangle.right.fill", | ||
] | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -406,7 +406,9 @@ class KeyboardViewController: UIInputViewController { | |
var i = 0 | ||
if completionOptions.count <= 3 { | ||
while i < completionOptions.count { | ||
if shiftButtonState == .caps { | ||
if shiftButtonState == .shift { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting, we were missing shift?? Great catch :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, suggestions were not handled properly for capitalised first-letter but it will be history after the merge. |
||
completionWords[i] = completionOptions[i].capitalize() | ||
} else if capsLockButtonState == .locked { | ||
completionWords[i] = completionOptions[i].uppercased() | ||
} else if currentPrefix.isCapitalized { | ||
if completionOptions[i].isUppercase { | ||
|
@@ -421,7 +423,9 @@ class KeyboardViewController: UIInputViewController { | |
} | ||
} else { | ||
while i < 3 { | ||
if shiftButtonState == .caps { | ||
if shiftButtonState == .shift { | ||
completionWords[i] = completionOptions[i].capitalize() | ||
} else if capsLockButtonState == .locked { | ||
completionWords[i] = completionOptions[i].uppercased() | ||
} else if currentPrefix.isCapitalized { | ||
if completionOptions[i].isUppercase { | ||
|
@@ -472,7 +476,7 @@ class KeyboardViewController: UIInputViewController { | |
} | ||
if shiftButtonState == .shift { | ||
completionWords.append(suggestion.capitalize()) | ||
} else if shiftButtonState == .caps { | ||
} else if capsLockButtonState == .locked { | ||
completionWords.append(suggestion.uppercased()) | ||
} else { | ||
completionWords.append(suggestion) | ||
|
@@ -492,7 +496,7 @@ class KeyboardViewController: UIInputViewController { | |
while i < 3 { | ||
if shiftButtonState == .shift { | ||
completionWords.append(baseAutosuggestions[i].capitalize()) | ||
} else if shiftButtonState == .caps { | ||
} else if capsLockButtonState == .locked { | ||
completionWords.append(baseAutosuggestions[i].uppercased()) | ||
} else { | ||
completionWords.append(baseAutosuggestions[i]) | ||
|
@@ -547,7 +551,7 @@ class KeyboardViewController: UIInputViewController { | |
while i < 3 { | ||
if shiftButtonState == .shift { | ||
completionWords.append(suggestionsLowerCasePrefix[i].capitalize()) | ||
} else if shiftButtonState == .caps { | ||
} else if capsLockButtonState == .locked { | ||
completionWords.append(suggestionsLowerCasePrefix[i].uppercased()) | ||
} else { | ||
let nounGenderQuery = "SELECT * FROM nouns WHERE noun = ?" | ||
|
@@ -574,7 +578,7 @@ class KeyboardViewController: UIInputViewController { | |
while i < 3 { | ||
if shiftButtonState == .shift { | ||
completionWords.append(suggestionsCapitalizedPrefix[i].capitalize()) | ||
} else if shiftButtonState == .caps { | ||
} else if capsLockButtonState == .locked { | ||
completionWords.append(suggestionsCapitalizedPrefix[i].uppercased()) | ||
} else { | ||
completionWords.append(suggestionsCapitalizedPrefix[i]) | ||
|
@@ -1875,6 +1879,14 @@ class KeyboardViewController: UIInputViewController { | |
styleIconBtn(btn: btn, color: keyCharColor, iconName: "keyboard.chevron.compact.down") | ||
} | ||
|
||
if key == SpecialKeys.indent { | ||
styleIconBtn(btn: btn, color: keyCharColor, iconName: "arrow.forward.to.line") | ||
} | ||
|
||
if key == SpecialKeys.capsLock { | ||
styleIconBtn(btn: btn, color: keyCharColor, iconName: "capslock") | ||
} | ||
|
||
if key == "shift" { | ||
styleIconBtn(btn: btn, color: keyCharColor, iconName: "shift") | ||
} | ||
|
@@ -1925,6 +1937,10 @@ class KeyboardViewController: UIInputViewController { | |
|
||
// Set the width of the key given device and the given key. | ||
btn.adjustKeyWidth() | ||
|
||
// Update the button style | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noting the comment for myself. |
||
btn.adjustButtonStyle() | ||
|
||
if key == "return" && proxy.keyboardType == .webSearch && ![.translate, .conjugate, .plural].contains(commandState) { | ||
// Override background color from adjustKeyWidth for "search" blue for web searches. | ||
styleIconBtn(btn: btn, color: .white.withAlphaComponent(0.9), iconName: "arrow.turn.down.left") | ||
|
@@ -2482,7 +2498,14 @@ class KeyboardViewController: UIInputViewController { | |
} | ||
|
||
case "shift": | ||
shiftButtonState = shiftButtonState == .normal ? .shift : .normal | ||
if capsLockButtonState == .locked { | ||
// Return capitalization to default | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice as well as we now have both states to account for :) |
||
capsLockButtonState = .normal | ||
shiftButtonState = .normal | ||
} else { | ||
shiftButtonState = shiftButtonState == .normal ? .shift : .normal | ||
} | ||
|
||
loadKeys() | ||
capsLockPossible = true | ||
|
||
|
@@ -2496,6 +2519,12 @@ class KeyboardViewController: UIInputViewController { | |
changeKeyboardToLetterKeys() | ||
autoCapAtStartOfProxy() | ||
|
||
case SpecialKeys.capsLock: | ||
switchToFullCaps() | ||
|
||
case SpecialKeys.indent: | ||
proxy.insertText("\t") | ||
|
||
case "selectKeyboard": | ||
advanceToNextInputMode() | ||
|
||
|
@@ -2612,9 +2641,7 @@ class KeyboardViewController: UIInputViewController { | |
|
||
// Caps lock given two taps of shift. | ||
if touch.tapCount == 2 && originalKey == "shift" && capsLockPossible { | ||
shiftButtonState = .caps | ||
loadKeys() | ||
conditionallySetAutoActionBtns() | ||
switchToFullCaps() | ||
} | ||
|
||
// To make sure that the user can still use the double space period shortcut after numbers and symbols. | ||
|
@@ -2657,6 +2684,15 @@ class KeyboardViewController: UIInputViewController { | |
} | ||
} | ||
|
||
private func switchToFullCaps() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another thing that we've been dealing with is that not enough of the code base is split into functions. I do some rounds from time to time and break some things out, but if you came across some parts where we can extract some code then by all means let me know or open an issue! |
||
// Return SHIFT button to normal state as the ALLCAPS button will be enabled | ||
shiftButtonState = .normal | ||
capsLockButtonState = capsLockButtonState == .normal ? .locked : .normal | ||
|
||
loadKeys() | ||
conditionallySetAutoActionBtns() | ||
} | ||
|
||
/// Defines the criteria under which delete is long pressed. | ||
/// | ||
/// - Parameters | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very intuitive :)