修复大小写切换后新输入字母不跟随转换,输入时根据当前大小写状态存储

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-07-21 22:46:18 +08:00
parent ccf0bc876b
commit c86e482e68
2 changed files with 6 additions and 1 deletions
@@ -218,6 +218,7 @@ final class QuizViewController: UIViewController {
if isSpelling { if isSpelling {
spellingHintLabel.text = "\(question.word.word.count) 个字母,补全空缺部分" spellingHintLabel.text = "\(question.word.word.count) 个字母,补全空缺部分"
spellingView.isUppercase = isUppercase
spellingView.configure(blankedWord: question.blankedWord, blankPositions: question.blankPositions) spellingView.configure(blankedWord: question.blankedWord, blankPositions: question.blankPositions)
if config.isStudyMode { if config.isStudyMode {
nextButton.isHidden = true nextButton.isHidden = true
@@ -425,6 +426,7 @@ final class QuizViewController: UIViewController {
isUppercase.toggle() isUppercase.toggle()
UserDefaults.standard.set(isUppercase, forKey: "spelling_uppercase") UserDefaults.standard.set(isUppercase, forKey: "spelling_uppercase")
updateCaseButton() updateCaseButton()
spellingView.isUppercase = isUppercase
questions = QuizGenerator.recase(questions, toUpper: isUppercase) questions = QuizGenerator.recase(questions, toUpper: isUppercase)
spellingView.updateCase(toUpper: isUppercase) spellingView.updateCase(toUpper: isUppercase)
} }
@@ -17,6 +17,8 @@ final class SpellingInputView: UIView, UITextFieldDelegate {
private var cursorView: UIView? private var cursorView: UIView?
private var inputEnabled = true private var inputEnabled = true
var isUppercase = false
var isComplete: Bool { var isComplete: Bool {
!filledBlanks.isEmpty && filledBlanks.allSatisfy { !$0.isEmpty } !filledBlanks.isEmpty && filledBlanks.allSatisfy { !$0.isEmpty }
} }
@@ -183,7 +185,8 @@ final class SpellingInputView: UIView, UITextFieldDelegate {
onChange?() onChange?()
} }
} else if let char = string.last, char.isLetter, cursorIndex < blankPositions.count { } else if let char = string.last, char.isLetter, cursorIndex < blankPositions.count {
filledBlanks[cursorIndex] = String(char).lowercased() let converted = isUppercase ? char.uppercased() : char.lowercased()
filledBlanks[cursorIndex] = converted
cursorIndex += 1 cursorIndex += 1
refreshBoxes() refreshBoxes()
popBox(atBlank: cursorIndex - 1) popBox(atBlank: cursorIndex - 1)