diff --git a/Keyboards/KeyboardsBase/KeyboardViewController.swift b/Keyboards/KeyboardsBase/KeyboardViewController.swift index 0f3445c7..9f38fdc9 100644 --- a/Keyboards/KeyboardsBase/KeyboardViewController.swift +++ b/Keyboards/KeyboardsBase/KeyboardViewController.swift @@ -2199,32 +2199,23 @@ class KeyboardViewController: UIInputViewController { switch originalKey { case "Scribe": - if proxy.selectedText != nil && [.idle, .selectCommand, .alreadyPlural, .invalid].contains(commandState) { // annotate word - if [.selectCommand, .alreadyPlural, .invalid].contains(commandState) { - commandState = .idle - } - emojisToShow = .zero - loadKeys() - selectedWordAnnotation(KVC: self) - } else { - if [.translate, - .conjugate, - .selectVerbConjugation, - .selectCaseDeclension, - .plural].contains(commandState) { // escape - commandState = .idle - deCaseVariantDeclensionState = .disabled - } else if [.idle, .alreadyPlural, .invalid].contains(commandState) { // ScribeKey - commandState = .selectCommand - activateBtn(btn: translateKey) - activateBtn(btn: conjugateKey) - activateBtn(btn: pluralKey) - } else { // escape - commandState = .idle - deCaseVariantDeclensionState = .disabled - } - loadKeys() + if [.translate, + .conjugate, + .selectVerbConjugation, + .selectCaseDeclension, + .plural].contains(commandState) { // escape + commandState = .idle + deCaseVariantDeclensionState = .disabled + } else if [.idle, .alreadyPlural, .invalid].contains(commandState) { // ScribeKey + commandState = .selectCommand + activateBtn(btn: translateKey) + activateBtn(btn: conjugateKey) + activateBtn(btn: pluralKey) + } else { // escape + commandState = .idle + deCaseVariantDeclensionState = .disabled } + loadKeys() case "return": if ![.translate, .conjugate, .plural].contains(commandState) { // normal return button @@ -2276,32 +2267,99 @@ class KeyboardViewController: UIInputViewController { } case "Translate": - commandState = .translate - // Always start in letters with a new keyboard. - keyboardState = .letters - conditionallyHideEmojiDividers() - loadKeys() - commandBar.textColor = keyCharColor - commandBar.attributedText = translatePromptAndColorPlaceholder + if let selectedText = proxy.selectedText { + queryWordToTranslate(queriedWordToTranslate: selectedText) + + if commandState == .invalid { // invalid state + loadKeys() + proxy.insertText(selectedText) + autoCapAtStartOfProxy() + commandBar.text = commandPromptSpacing + invalidCommandMsg + commandBar.isShowingInfoButton = true + commandBar.textColor = keyCharColor + return + } else { // functional commands above + autoActionState = .suggest + commandState = .idle + autoCapAtStartOfProxy() + loadKeys() + conditionallyDisplayAnnotation() + } + } else { + commandState = .translate + // Always start in letters with a new keyboard. + keyboardState = .letters + conditionallyHideEmojiDividers() + loadKeys() + commandBar.textColor = keyCharColor + commandBar.attributedText = translatePromptAndColorPlaceholder + } case "Conjugate": - commandState = .conjugate - conditionallyHideEmojiDividers() - loadKeys() - commandBar.textColor = keyCharColor - commandBar.attributedText = conjugatePromptAndColorPlaceholder + if let selectedText = proxy.selectedText { + resetVerbConjugationState() + let verbInTable = isVerbInConjugationTable(queriedVerbToConjugate: selectedText) + if verbInTable { + commandState = .selectVerbConjugation + loadKeys() // go to conjugation view + return + } else { + commandState = .invalid + loadKeys() + proxy.insertText(selectedText) + autoCapAtStartOfProxy() + commandBar.text = commandPromptSpacing + invalidCommandMsg + commandBar.isShowingInfoButton = true + commandBar.textColor = keyCharColor + return + } + } else { + commandState = .conjugate + conditionallyHideEmojiDividers() + loadKeys() + commandBar.textColor = keyCharColor + commandBar.attributedText = conjugatePromptAndColorPlaceholder + } case "Plural": - commandState = .plural - if controllerLanguage == "German" { // capitalize for nouns - if shiftButtonState == .normal { - shiftButtonState = .shift + if let selectedText = proxy.selectedText { + queryPluralNoun(queriedNoun: selectedText) + + if [.invalid, .alreadyPlural].contains(commandState) { + loadKeys() + + if commandState == .invalid { + proxy.insertText(selectedText) + commandBar.text = commandPromptSpacing + invalidCommandMsg + commandBar.isShowingInfoButton = true + } else { + commandBar.isShowingInfoButton = false + if commandState == .alreadyPlural { + commandBar.text = commandPromptSpacing + alreadyPluralMsg + } + } + autoCapAtStartOfProxy() + commandBar.textColor = keyCharColor + return + } else { // functional commands above + autoActionState = .suggest + commandState = .idle + autoCapAtStartOfProxy() + loadKeys() + conditionallyDisplayAnnotation() } + } else { + commandState = .plural + if controllerLanguage == "German" { // capitalize for nouns + if shiftButtonState == .normal { + shiftButtonState = .shift + } + } + conditionallyHideEmojiDividers() + loadKeys() + commandBar.textColor = keyCharColor + commandBar.attributedText = pluralPromptAndColorPlaceholder } - conditionallyHideEmojiDividers() - loadKeys() - commandBar.textColor = keyCharColor - commandBar.attributedText = pluralPromptAndColorPlaceholder case "shiftFormsDisplayLeft": shiftLeft() @@ -2751,7 +2809,7 @@ class KeyboardViewController: UIInputViewController { && (originalKey == spaceBar || originalKey == languageTextForSpaceBar) && proxy.documentContextBeforeInput?.count != 1 && doubleSpacePeriodPossible { - // The fist condition prevents a period if the prior characters are spaces as the user wants a series of spaces. + // The first condition prevents a period if the prior characters are spaces as the user wants a series of spaces. if proxy.documentContextBeforeInput?.suffix(2) != " " && ![.translate, .conjugate, .plural].contains(commandState) { proxy.deleteBackward() proxy.insertText(". ") diff --git a/Keyboards/KeyboardsBase/ScribeFunctionality/Annotate.swift b/Keyboards/KeyboardsBase/ScribeFunctionality/Annotate.swift index 43199113..55697d3a 100644 --- a/Keyboards/KeyboardsBase/ScribeFunctionality/Annotate.swift +++ b/Keyboards/KeyboardsBase/ScribeFunctionality/Annotate.swift @@ -45,7 +45,7 @@ let prepAnnotationConversionDict = [ "Russian": ["Acc": "Вин", "Dat": "Дат", "Gen": "Род", "Loc": "Мес", "Pre": "Пре", "Ins": "Инс"] ] -/// The base function for annotation that's accessed by `selectedWordAnnotation` and `typedWordAnnotation`. +/// The base function for annotation that's accessed by `typedWordAnnotation`. /// /// - Parameters /// - wordToAnnotate: the word that an annotation should be created for. @@ -217,22 +217,6 @@ func wordAnnotation(wordToAnnotate: String, KVC: KeyboardViewController) { } } -/// Annotates a word after it's selected and the Scribe key is pressed. -/// -/// - Parameters -/// - KVC: the keyboard view controller. -func selectedWordAnnotation(KVC: KeyboardViewController) { - wordToCheck = proxy.selectedText ?? "" - if !wordToCheck.isEmpty { - if !languagesWithCapitalizedNouns.contains(controllerLanguage) { - wordToCheck = wordToCheck.lowercased() - } - wordAnnotation(wordToAnnotate: wordToCheck, KVC: KVC) - } else { - return - } -} - /// Annotates a typed word after a space or auto action. /// /// - Parameters diff --git a/Keyboards/KeyboardsBase/ScribeFunctionality/Conjugate.swift b/Keyboards/KeyboardsBase/ScribeFunctionality/Conjugate.swift index 50891cf1..2f29db08 100644 --- a/Keyboards/KeyboardsBase/ScribeFunctionality/Conjugate.swift +++ b/Keyboards/KeyboardsBase/ScribeFunctionality/Conjugate.swift @@ -66,12 +66,12 @@ func returnDeclension(keyPressed: UIButton) { } if !(wordPressed.contains("/") || wordPressed.contains("∗")) { - proxy.insertText(wordPressed + " ") + proxy.insertText(wordPressed + getOptionalSpace()) deCaseVariantDeclensionState = .disabled autoActionState = .suggest commandState = .idle } else if controllerLanguage == "Russian" { // pronoun selection paths not implemented for Russian - proxy.insertText(wordPressed + " ") + proxy.insertText(wordPressed + getOptionalSpace()) deCaseVariantDeclensionState = .disabled autoActionState = .suggest commandState = .idle @@ -204,7 +204,12 @@ func triggerVerbConjugation(commandBar: UILabel) -> Bool { let endIndex = commandBarText.index(commandBarText.endIndex, offsetBy: -1) verbToConjugate = String(commandBarText[startIndex ..< endIndex]) } - verbToConjugate = String(verbToConjugate.trailingSpacesTrimmed) + + return isVerbInConjugationTable(queriedVerbToConjugate: verbToConjugate) +} + +func isVerbInConjugationTable(queriedVerbToConjugate: String) -> Bool { + verbToConjugate = String(queriedVerbToConjugate.trailingSpacesTrimmed) // Check to see if the input was uppercase to return an uppercase conjugation. let firstLetter = verbToConjugate.substring(toIdx: 1) @@ -244,19 +249,19 @@ func returnConjugation(keyPressed: UIButton, requestedForm: String) { // Don't return a space as well as we have a perfect verb and the cursor will be between. proxy.insertText(wordToReturn.capitalize()) } else { - proxy.insertText(wordToReturn.capitalized + " ") + proxy.insertText(wordToReturn.capitalized + getOptionalSpace()) } } else { - proxy.insertText(wordToReturn + " ") + proxy.insertText(wordToReturn + getOptionalSpace()) } } else if formsDisplayDimensions == .view2x2 { wordToReturn = LanguageDBManager.shared.queryVerb(of: verbToConjugate, with: outputCols)[0] potentialWordsToReturn = wordToReturn.components(separatedBy: " ") if inputWordIsCapitalized { - proxy.insertText(wordToReturn.capitalized + " ") + proxy.insertText(wordToReturn.capitalized + getOptionalSpace()) } else { - proxy.insertText(wordToReturn + " ") + proxy.insertText(wordToReturn + getOptionalSpace()) } } diff --git a/Keyboards/KeyboardsBase/ScribeFunctionality/Plural.swift b/Keyboards/KeyboardsBase/ScribeFunctionality/Plural.swift index 8d25dca7..90757025 100644 --- a/Keyboards/KeyboardsBase/ScribeFunctionality/Plural.swift +++ b/Keyboards/KeyboardsBase/ScribeFunctionality/Plural.swift @@ -36,7 +36,12 @@ func queryPlural(commandBar: UILabel) { let endIndex = commandBarText.index(before: commandBarText.endIndex) noun = String(commandBarText[startIndex ..< endIndex]) } - noun = String(noun.trailingSpacesTrimmed) + + queryPluralNoun(queriedNoun: noun) +} + +func queryPluralNoun(queriedNoun: String) { + var noun = String(queriedNoun.trailingSpacesTrimmed) // Check to see if the input was uppercase to return an uppercase plural. inputWordIsCapitalized = false @@ -54,12 +59,12 @@ func queryPlural(commandBar: UILabel) { if wordToReturn != "isPlural" { if inputWordIsCapitalized { - proxy.insertText(wordToReturn.capitalized + " ") + proxy.insertText(wordToReturn.capitalized + getOptionalSpace()) } else { - proxy.insertText(wordToReturn + " ") + proxy.insertText(wordToReturn + getOptionalSpace()) } } else { - proxy.insertText(noun + " ") + proxy.insertText(noun + getOptionalSpace()) commandState = .alreadyPlural } } diff --git a/Keyboards/KeyboardsBase/ScribeFunctionality/Translate.swift b/Keyboards/KeyboardsBase/ScribeFunctionality/Translate.swift index d8d9d03e..d3b9ac8c 100644 --- a/Keyboards/KeyboardsBase/ScribeFunctionality/Translate.swift +++ b/Keyboards/KeyboardsBase/ScribeFunctionality/Translate.swift @@ -35,7 +35,12 @@ func queryTranslation(commandBar: UILabel) { let endIndex = commandBarText.index(commandBarText.endIndex, offsetBy: -1) wordToTranslate = String(commandBarText[startIndex ..< endIndex]) } - wordToTranslate = String(wordToTranslate.trailingSpacesTrimmed) + + queryWordToTranslate(queriedWordToTranslate: wordToTranslate) +} + +func queryWordToTranslate(queriedWordToTranslate: String) { + wordToTranslate = String(queriedWordToTranslate.trailingSpacesTrimmed) // Check to see if the input was uppercase to return an uppercase conjugation. inputWordIsCapitalized = wordToTranslate.substring(toIdx: 1).isUppercase @@ -48,8 +53,8 @@ func queryTranslation(commandBar: UILabel) { } if inputWordIsCapitalized { - proxy.insertText(wordToReturn.capitalized + " ") + proxy.insertText(wordToReturn.capitalized + getOptionalSpace()) } else { - proxy.insertText(wordToReturn + " ") + proxy.insertText(wordToReturn + getOptionalSpace()) } } diff --git a/Keyboards/KeyboardsBase/Utilities.swift b/Keyboards/KeyboardsBase/Utilities.swift index 006e9f40..f851d115 100644 --- a/Keyboards/KeyboardsBase/Utilities.swift +++ b/Keyboards/KeyboardsBase/Utilities.swift @@ -44,3 +44,12 @@ func get_iso_code(keyboardLanguage: String) -> String { return iso } + +/// Checks if an extra space is needed in the text field when generated text is inserted +func getOptionalSpace() -> String { + if proxy.documentContextAfterInput?.first == " " { + return "" + } else { + return " " + } +} diff --git a/Scribe/InstallationTab/InstallationVC.swift b/Scribe/InstallationTab/InstallationVC.swift index 5d96e49d..76f936af 100644 --- a/Scribe/InstallationTab/InstallationVC.swift +++ b/Scribe/InstallationTab/InstallationVC.swift @@ -226,10 +226,8 @@ class InstallationVC: UIViewController { // Sets the font size for the text in the app screen and corresponding UIImage icons. if DeviceType.isPhone { if UIScreen.main.bounds.width > 413 || UIScreen.main.bounds.width <= 375 { - print(UIScreen.main.bounds.width) fontSize = UIScreen.main.bounds.height / 59 } else if UIScreen.main.bounds.width <= 413 && UIScreen.main.bounds.width > 375 { - print(UIScreen.main.bounds.width) fontSize = UIScreen.main.bounds.height / 50 }