Skip to content
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

Fixes #380: Code quality improvement by replacing while with for loop #395

Merged
merged 1 commit into from
Jan 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 18 additions & 29 deletions Keyboards/KeyboardsBase/KeyboardViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,8 @@ class KeyboardViewController: UIInputViewController {
let completionOptions = queryAutocompletions(word: currentPrefix)

if completionOptions[0] != "" {
var i = 0
if completionOptions.count <= 3 {
while i < completionOptions.count {
for i in 0 ..< completionOptions.count {
if shiftButtonState == .shift {
completionWords[i] = completionOptions[i].capitalize()
} else if capsLockButtonState == .locked {
Expand All @@ -419,10 +418,9 @@ class KeyboardViewController: UIInputViewController {
} else {
completionWords[i] = completionOptions[i]
}
i += 1
}
} else {
while i < 3 {
for i in 0 ..< 3 {
if shiftButtonState == .shift {
completionWords[i] = completionOptions[i].capitalize()
} else if capsLockButtonState == .locked {
Expand All @@ -436,7 +434,6 @@ class KeyboardViewController: UIInputViewController {
} else {
completionWords[i] = completionOptions[i]
}
i += 1
}
}
}
Expand All @@ -460,9 +457,8 @@ class KeyboardViewController: UIInputViewController {
let prefix = proxy.documentContextBeforeInput?.components(separatedBy: " ").secondToLast() ?? ""

completionWords = [String]()
var i = 0
let query = "SELECT * FROM verbs WHERE verb = ?"
while i < 3 {
for i in 0 ..< 3 {
// Get conjugations of the preselected verbs.
let args = [verbsAfterPronounsArray[i]]
let outputCols = [pronounAutosuggestionTenses[prefix.lowercased()]!]
Expand All @@ -481,27 +477,24 @@ class KeyboardViewController: UIInputViewController {
} else {
completionWords.append(suggestion)
}
i += 1
}
}

/// Generates an array of three words that serve as baseline autosuggestions.
func getDefaultAutosuggestions() {
var i = 0
completionWords = [String]()
if allowUndo {
completionWords.append(previousWord)
i += 1
}
while i < 3 {
for i in 0 ..< 3 {
if (allowUndo) {
completionWords.append(previousWord)
continue
}
if shiftButtonState == .shift {
completionWords.append(baseAutosuggestions[i].capitalize())
} else if capsLockButtonState == .locked {
completionWords.append(baseAutosuggestions[i].uppercased())
} else {
completionWords.append(baseAutosuggestions[i])
}
i += 1
}
}

Expand Down Expand Up @@ -543,12 +536,11 @@ class KeyboardViewController: UIInputViewController {
let suggestionsCapitalizedPrefix = queryDBRow(query: query, outputCols: outputCols, args: argsCapitalize)
if suggestionsLowerCasePrefix[0] != "" {
completionWords = [String]()
var i = 0
if allowUndo {
completionWords.append(previousWord)
i += 1
}
while i < 3 {
for i in 0 ..< 3 {
if (allowUndo) {
completionWords.append(previousWord)
continue
}
if shiftButtonState == .shift {
completionWords.append(suggestionsLowerCasePrefix[i].capitalize())
} else if capsLockButtonState == .locked {
Expand All @@ -566,24 +558,21 @@ class KeyboardViewController: UIInputViewController {
completionWords.append(suggestionsLowerCasePrefix[i])
}
}
i += 1
}
} else if suggestionsCapitalizedPrefix[0] != "" {
completionWords = [String]()
var i = 0
if allowUndo {
completionWords.append(previousWord)
i += 1
}
while i < 3 {
for i in 0 ..< 3 {
if (allowUndo) {
completionWords.append(previousWord)
continue
}
if shiftButtonState == .shift {
completionWords.append(suggestionsCapitalizedPrefix[i].capitalize())
} else if capsLockButtonState == .locked {
completionWords.append(suggestionsCapitalizedPrefix[i].uppercased())
} else {
completionWords.append(suggestionsCapitalizedPrefix[i])
}
i += 1
}
} else {
getDefaultAutosuggestions()
Expand Down